An earthquake with a preliminary magnitude of 4.2 shook parts of Kyoto and Osaka prefectures early Wednesday morning.