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
Answer from Rishi on Stack OverflowI 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).
python - import mysql.connector could not be resolved pylance - Stack Overflow
Import Error. I can't import mysql-connector in Python - Stack Overflow
python - ImportError: No module named mysql.connector using Python2 - Stack Overflow
python - How to fix "Error: No module named mysql.connector" - Stack Overflow
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
>>>
Depending on your python version and how you installed it, it is possible that mysql connector isn't installed, you can install it with pip
To install mysql connector:
pip install mysql-connector-python
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation: https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2. Pip3 is just for python3. You must use pip2 or pip2.7 for work with python2. Search if you got the pip2 package installed is not then install it.
You might want to check out the following article:
Can not get mysql-connector-python to install in virtualenv (Stackoverflow)
The accepted answer states the following:
Several things. There is an inconsistency in package naming so you may want to do:
pip search mysql-connectorto find out what it is called on your platform. I got two results
mysql-connector-pythonandmysql-connector-repackaged.so try this first:
pip install mysql-connector-pythonthis may additionally give an error like this:
Some externally hosted files were ignored (use --allow-external mysql-connector-python to allow).so finally this should do the job:
pip install mysql-connector-python --allow-external mysql-connector-python
The following command solved the issue for me.
pip install mysql-connector-python-rf
This post expands a little on the differences between mysql-connector-python and the -rf suffixed variant.
I already did the whole pip install mysql-connector-python thing, but the error’s still haunting me. How am I supposed to sleep in peace. Need help
So i bought a linux server the other day, and followed this tutorial to install mysql: https://www.youtube.com/watch?v=WltqUaqxBH8
And I got no errors while running the mysql queries, but i get an error when i run my python file:
import mysql.connector
conn = mysql.connector.connect(
host= '216.137.179.68',
user='app',
passwd="Cian62016!"
)
mycursor = conn.cursor()
mycursor.execute("SHOW DATABASES")
myresponce = mycursor.fetchone()
print(myresponce)
conn.close()Error:
Traceback (most recent call last):
File "mysqlConnectorTest.py", line 5, in <module>
conn = mysql.connector.connect(
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/connection.py", line 95, in __init__
self.connect(**kwargs)
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 716, in connect
self._open_connection()
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/connection.py", line 208, in _open_connection
self._do_auth(self._user, self._password,
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/connection.py", line 137, in _do_auth
packet = self._protocol.make_auth(
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/protocol.py", line 99, in make_auth
packet += self._auth_response(client_flags, username, password,
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "/home/alexander/.local/lib/python3.8/site-packages/mysql/connector/authentication.py", line 190, in get_auth_plugin
raise errors.NotSupportedError(
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supportedAnd the mysql connector was just installed using:
pip3 install mysql.connector
Any Thoughts on how to help would be greatly appreciated!!!
Thanks!