ModuleNotFoundError No module named mysql

1.2K    Asked by NicolaYoung in SQL Server , Asked on Jul 27, 2021

As I am trying to connect MySQL with python. But I am getting this below error.

import mysql.connector
ModuleNotFoundError                       Traceback (most recent call last)
----> 1 import mysql.connector

ModuleNotFoundError: No module named 'mysql'

Answered by Sam Fraser

You need to install mysql-connector to connect Python with MySQL. You can use the below command to install this in your system.

C:UsersNadeem Akhter>pip install mysql-connector-python-rf
Collecting mysql-connector-python-rf

  Downloading mysql-connector-python-rf-2.2.2.tar.gz (11.9 MB)

     |████████████████████████████████| 11.9 MB 111 kB/s

Building wheels for collected packages: mysql-connector-python-rf

  Building wheel for mysql-connector-python-rf ( ... done

  Created wheel for mysql-connector-python-rf: filename=mysql_connector_python_rf-2.2.2-cp36-cp36m-win_amd64.whl size=249460 sha256=b3b15baa6cbb68935e2c221725ca7133f2714623b26531f2e34f56b0e3d051ee

        Stored in directory: c:users
adeem akhterppdatalocalpipcachewheels) f^443b7177ee453aa9d6c8862fc2d1a1ea8ff8ee0999d1971

Successfully built mysql-connector-python-rf

Installing collected packages: mysql-connector-python-rf

Successfully installed mysql-connector-python-rf-2.2.2

Or another solution is to install a corresponding module for the Python version:

  • For Python 3. x version install mysql connector with below command. pip3 install mysql-connector.
  • For Python 2. x version install mysql connector with below command. pip install mysql-connector.

On Linux servers, run the below command.

Your Answer


Parent Categories