I have the same issue. I use visual code from Ms and the remote debugging over an ssh. I am able to do all mysql while in the debugger but running on command line does not work. The DB is logged in as root as this was the only way I could make it work.
pi@raspberrypi:~/blescan/iBeacon-Scanner-$ pip search mysql-connector | grep --color mysql-connector-python mysql-connector-python (8.0.20) - MySQL driver written in Python mysql-connector-python-dd (2.0.2) - MySQL driver written in Python mysql-connector-python-rf (2.2.2) - MySQL driver written in Python pi@raspberrypi:~/blescan/iBeacon-Scanner-$ pip install mysql-connector-python-rf Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: mysql-connector-python-rf in /home/pi/.local/lib/python3.7/site-packages (2.2.2) pi@raspberrypi:~/blescan/iBeacon-Scanner-$ sudo python3 BeaconClass.py Traceback (most recent call last): File "BeaconClass.py", line 7, in <module> import mysql.connector as mariadb ModuleNotFoundError: No module named 'mysql' pi@raspberrypi:~/blescan/iBeacon-Scanner-$ -- https://mail.python.org/mailman/listinfo/python-list