They will hope it is fourth time lucky in their two-legged playoff tie for a place at the 2014 tournament in Brazil having failed to reach the finals that way in three previous attempts.
The draw for the playoffs is on Oct. 21 in Zurich.
Yevgen Seleznov gave Ukraine an early lead with a penalty after 13 minutes and Serbia-born striker Marko Devic doubled the advantage by firing low into the far corner three minutes later.
Seleznov struck again in the 19th before Devic headed home their fourth goal after 51 minutes, with both goals laid on by Ruslan Rotan who provided perfect crosses from the left.
Andriy Yarmolenko rifled home a fifth with a left-foot shot into the far corner four minutes later.
Devic then grabbed his hat-trick from the penalty spot two minutes later after San Marino defender Marco Palazzi brought him down and was sent off.
Roman Bezus scored in the 66th only a minute after coming off the bench and defender Vitaliy Mandzyuk headed home their eighth goal from a corner just before the final whistle with San Marino having Alessandro Della Valle sent off late on.
The final result saw Ukraine finish only one goal short of their record 9-0 victory away to San Marino last month.