Modulenotfounderror: no module named ‘mysql’

In this article, we will provide detailed solutions on how to solve the error modulenotfounderror: no module named mysql.

Furthermore, the MySQL is one of the systems which applies SQL to manage the data. The ‘no module named mysql’ error has occurred.

If the MySQL is utilized with Python in a Linux, Windows, MacOS, Anaconda, and CentOS.

Moreover, the error no module named ‘mysql appears because the system environment is unable to find the installed mysql.

Also you may read: Modulenotfounderror no module named ‘pygame’

How to solve the no module named mysql?

Time needed: 3 minutes

In your project directory folder open CMD(Command Prompt) and install the mysql-connector-python package.

  • Solution 1: Install mysql in Python 2

    The following command to install mysql in Python 2:
    pip install mysql-connector-python

  • Solution 2: Install mysql in Python 3

    This is the command to install mysql in Python 3:
    pip3 install mysql-connector-python

    and Install Pip in Python 3:

    python3 -m pip install mysql-connector-python

  • Solution 3: Install mysql in for Getting Permissions Error

    This is the command to install mysql for Getting Permissions Error.
    sudo pip3 install mysql-connector-python

    or

    pip install mysql-connector-python –user

  • Solution 4: Install Pip in Path Environment Variable

    This is the following command to install the Pip in Path Environment Variable with MySQL.
    python -m pip install mysql-connector-python

  • Solution 5: Install py alias(windows)

    This is the following command to install mysql in py alias(windows):
    py -m pip install mysql-connector-python

  • Solution 6: Install in Anaconda

    This is the following command to install mysql in Anaconda:
    conda install -c anaconda mysql-connector-python

  • Solution 7: Install in Jupyter Notebook

    This is the following command to install mysql in Jupyter Notebook:
    !pip install mysql-connector-python

The Simple Causes of Error’s:

These are the common reasons that the modulenotfounderror: no module named mysql:

  1. The “mysql-connector-python” module is not installed.
  2. You installed the module in a various python version compared to the one you’re using.
  3. You installed the module globally not within your virtual environment.
  4. You run the IDE within an incorrect python version.

Read also: Modulenotfounderror: no module named skimage [SOLVED]

Conclusion

To conclude, in this article if you encountered this error “ModuleNotFoundError: No module named ‘mysql“. The above solutions are the best way to solve your errors.

Leave a Comment