0 likes | 8 Views
mysql module not found is an error that occurs in python. It appears like ModuleNotError: No module named 'mysql.' This error occurs when you forget to install a module called mysql-connector-python in a preferable environment.
E N D
MODULENOTFOUNDERROR No module named ‘mysql’ in Python www.tutorialandexample.com
INTRODUCTION One common reason for this error is that the MySQL module is not installed on your system. Try importing the module in a Python script to check if this is the case. If the module is not installed, the interpreter will raise the “ModuleNotFoundError.”
MYSQL PYTHON : ABOUT MYSQL •MySQL is a fast, easy-to-use relational database. It is currently the most popular open-source database •MySQL is used for many small and big businesses. It is developed, marketed, and supported by MySQL AB, a Swedish company. It is written in C and C++. •MySQL is an open-source database, so you don’t have to pay a single penny to use it. MySQL Features •MySQL is a fast, easy-to-use relational database. •MySQL is used for many small and big businesses. •MySQL is an open-source database, so you don’t have to pay.
ModuleNotError: No module named 'mysql.' MySQL module not found is an error that occurs in Python. This error occurs when you forget to install a module called mysql-connector-python in a preferable environment.
pip install mysql-connector-python To fix this error, we install a new module by using a command called If this error occurs, you have to open the project's root directory and install the module by using the above command. This command only works in a virtual environment. Or by using Python 2.
For Python 3, use the command below: pip3 install mysql-connector-python
if you get the same error while working in python 3, then we use the below command for it for anaconda, we use the below command sometimes you won't get pip in the PATH environment variable then we use the bellow command to fix that error By installing this module, sometimes you might get a permission error. To fix that, we use the command below conda install -c anaconda mysql-connector-python python -m pip install mysql-connector-python sudo pip3 install mysql-connector-python python3 -m pip install mysql-connector-python
After installing the mysql-connector-python, we have to import that again in the code to use it. For example, let us see an example code: import mysql.connector # Connect to server cnx = mysql.connector.connect( host="127.0.0.1", port=3305, user="andy", password="$unrise_123") # Get a cursor cur = cnx.cursor() # Execute a query cur.execute("SELECT CURDATE()") # Fetch one result row = cur.fetchone() print("Current date is: {0}".format(row[0])) # Close connection' cnx.close() Output: Current date is: {0}
Few reasons for the error ModuleNotFoundError • Not having the pre-installed package mysql-connector-python we can -install it by using the pip install mysql-connector-python. • If you install the package of another version without checking the version of your system, an error occurs • Whenever we install the package worldwide, we must use the virtual environment, or an error occurs. • If the Python version of the IDE you are working on, you will get an error. • If you cover the name of the official module by naming the nodule mysql.py • Anytime you use a module name as a variable name, the variable name will import the variable.
PRESENTED BY JAVATPOINT • THANK YOU VERY MUCH! www.tutorialandexample.com