nameerror: name _mysql is not defined error occurs while connecting python end application with MySQL DB due to incompatibility or client/ connector unavailability. Typically There is a process to connect any SQL DB with Python, Here we need a connector that fulfills the requirement of request routing, connection development, and driver, etc. Specific to this error, if you get this error (name _mysql is not defined) you should check the root cause in the mentioned order. Because we will start with the most common scenarios with the rare and complex ones. If you change the order you may require extra time to fix it. Well, let’s, deep dive, into the solution.
Since this error is generic so we made the solution stepwise. Please follow the same.
Firstly and the easiest thing which we should focus on is verifying the connection credentials. If we make any mistake we encounter this error. The default Connection Credential is below. Please double-check if you have modified anything into it.
mysql://root:@localhost/test
Secondly, As we mentioned check if we have installed the connector and server properly. If we are not sure we should reinstall them to remove all the incompatibility.
pip install mysql
conda install -c conda-forge mysql
Finally Here are some sets of commands to run and get MySQL to install.
wget https://github.com/farcepest/MySQL-python/tarball/master -O MySQL-python.tar.gz
tar -xvf MySQL-python.tar.gz
cd farcepest-MySQL-python-*
sudo python setup.py install
Most Importantly, There are some dependent libraries in which Operating System needs to run a python application with MySQL Database. If the other solution is not working then try the below command.
sudo apt-get install libmysqlclient-dev
brew install mysql-connector-c
Thanks
Data Science Learner Team