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
I received the following error message:
Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> import mysql.connector ImportError: No module named 'mysql'
I can't figure out why MySQL is not being recognized.
The Python "ModuleNotFoundError: No module named 'mysql'" occurs when we forget to install the mysql-connector-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install mysql-connector-python command.
First, run the pip install mysql-connector command in Spyder IPython Console(Where executions are done) and when execution is finished then restart kernel after that you can use import mysql. connector .
I was facing the similar issue. My env details - Python 2.7.11 pip 9.0.1 CentOS release 5.11 (Final)
Error on python interpreter -
>>> import mysql.connector Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named mysql.connector >>>
Use pip to search the available module -
$ pip search mysql-connector | grep --color mysql-connector-python mysql-connector-python-rf (2.2.2) - MySQL driver written in Python mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf -
$ pip install mysql-connector-python-rf
Verify
$ python Python 2.7.11 (default, Apr 26 2016, 13:18:56) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mysql.connector >>>
Thanks =)
For python3 and later use the next command: $ pip3 install mysql-connector-python-rf
Use pip3 install mysql-connector
to install the python packaged (if you are using Python 3. For Python 2 you can use pip
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With