The city was founded on July 14, 1774, by Barreto Leme. It was initially a simple outpost on the way to Minas Gerais and Goiás serving the "Bandeirantes" who were in search of precious minerals and Indian slaves. In the first half of the 19th century, Campinas became a growing population center, with many coffee, cotton and sugarcane farms.
The construction of a railway linking the city of São Paulo to Santos' seaport, in 1867, was very important for its growth. In the second half of the 19th century, with the abolition of slavery, farming and industrialization attracted many foreign immigrants to replace the lost manpower, mainly from Italy.
Coffee became an important export and the city became wealthy. In consequence, a large service sector was established to serve the growing population, and in the first decades of the 20th century, Campinas could already boast of an opera house, theaters, banks, movie theaters, radio stations, a philharmonic orchestra, two newspapers (Correio Popular and Diário do Povo), a good public education system (with the Escola Normal de Campinas and the Colégio Culto à Ciência), and hospitals, such as the Santa Casa de Misericórdia (a charity for poor people) and the Casa de Saúde de Campinas (for the Italian community, formerly known as Circolo Italiani Uniti), and the most important Brazilian research center in agricultural sciences, the Instituto Agronômico de Campinas, which was founded by Emperor Pedro II. Finally, the construction of the first Brazilian highway in 1938, between Campinas and São Paulo, the Anhanguera Highway, was a turning point in the integration of Campinas into the rest of the state.
Campinas was the birthplace of opera composer Carlos Gomes (1836 — 1896) and of the President of the Republic Campos Salles (1841 — 1913). It was home for 49 years to Hércules Florence, reputed as one of the early inventors of photography, photocopying and the mimeograph.