mysql Debian based - Python 3.11 Configuration Setup w/ Pycharm
mysql Debian based - Python 3.11 Configuration Setup w/Pycharm
Getting a mysql connector to work in a Debian based environment is actually messy. Really messy. So messy in fact - it required it's own guide after reading dozens of tidbit guides throughout the Internet. Once one can finally figure it out - you only do yourself justice to document it to yourself.
Python 3.9 will not cleanly install witih mysql-connector. Just don't use it.
To make work:
- Set Pycharm to recognize Python 3.11:
2. Build yourself some template code to test the mysql connector as in:
import mysql.connector
cnx = mysql.connector.connect(user='root', password='password', host='192.168.1.3', database='', auth_plugin='mysql_native_password')
cnx.close()
3. Alter the permissions in your mysql so that it can work with mysql_native_password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';
If you need a mysql create user guide it is here:
4. Clean out mysql-connector / mysql-connector-python and reinstall:
- You pretty much have to add option '--break-system-packages' to everything you install and uninstall as it is pushing to virtual environments:
sudo pip3 uninstall mysql-connector --break-system-packages
sudo pip3 uninstall mysql-connector-python --break-system-packages
sudo pip3 install mysql-connector-python --break-system-packages
Now step-debug your code to confirm that you have a working connector:
In the debug section you will see your proof: