Mechanicsburg is a borough in Cumberland County, Pennsylvania, United States. The borough is eight miles west of Harrisburg. It is part of the Harrisburg–Carlisle metropolitan statistical area. As of the 2020 census, the population was 9,311, up from 8,981 recorded at the 2010 census.