ImportError: No module named 'MySQL'

后端 未结 17 1714
轮回少年
轮回少年 2020-12-12 17:40

I have downloaded the Connector/Python for MySQL successfully. I used the following code in Python\'s shell to test my connection:

import mysql.connector

17条回答
  •  -上瘾入骨i
    2020-12-12 18:41

    just a note, I just installed mysql on an ubuntu 16.04 server. I tried different options in the following order:

    • using the package from repository sudo apt-get install python-mysqldb: Was installed correctly, but unfortunatelly python returned ImportError: No module named 'mysql'
    • using the ubuntu package from Mysql: wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python_2.1.4-1ubuntu16.04_all.deb. Installed correctly with sudo dpckg -i package_name, but python returned the same error.
    • using tar.gz file, installing with python, worked ok.
      • wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.6.tar.gz (used 2.1.4 at that time)
      • tar -xf mysql-connector-python-2.1.6.tar.gz
      • cd mysql-connector-python-2.1.6/
      • sudo python3 setup.py install

    Did not investigate why the first two failed, might try later. Hope this helps someone.

提交回复
热议问题