The earthquake, which struck just before 2 a.m., had a preliminary magnitude of 2.2 and was centered about 20 miles north of the city.