They are not the same.
An optometrist is a Doctor of Optometry (OD) who is qualified to examine and diagnose diseases of the eye, diagnose vision problems, and prescribe eyeglasses and contact lenses. ODs complete a four-year post-graduate program.
An ophthalmologist is a Medical Doctor (MD) who specializes in eye and vision health. S/he is qualified to do all the things an optometrist may do and is also qualified to perform eye surgery. Ophthalmologists complete the training to become a doctor and then do a three-year program of specialization.
There also exists the job of optician. Opticians fit and dispense eyeglasses and contact lenses. Some opticians manufacture the lenses they sell. The training programs for opticians are far shorter than those for optometrists and ophthalmologists.
People often buy their glasses from their optometrist. Many buy them from dispensing opticians, who may have their own shops or may be part of a chain of shops.
Hope this is helpful,