ModuleNotFoundError: No module named ‘mysql’

When I tried to connect to MySQL from Python received below error.

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'mysql'

Reason:

We have to install mysql connector or corresponding mysql connector for Python version.

Solution:

The solution is to install corresponding module for Python version:

1. For Python 3.x version install mysql connector with below command.

pip3 install mysql-connector

2. For Python 2.x version install mysql connector with below command.

pip install mysql-connector

3. On Linux servers, run the below command.

sudo apt-get install python3-mysql.connector

Verification:

1. Open command prompt or terminal:

run python or python3

2. run the command import mysql.connector from Jupyter notebook or Python shell.

Leave a Reply

Your email address will not be published. Required fields are marked *