Marko Devic opened the scoring for the hosts after only 11 minutes as they perhaps predictably enjoyed the bulk of possession in Lviv.
Ukraine continued to besiege the San Marino goal with five attempts on target in the opening 20 minutes.
Edmar did score and Yevhen Khacheridi made it 4-0 on the stroke of half time.
San Marino were under pressure almost immediately as Ukraine scored two more in the opening minutes of the second half through Yevhen Konoplyanka and Khacheridi's second.
The win keeps Ukraine one point behind England and means that should Roy Hodgson's side lose in Kiev, their World Cup fate will be out of their hands.