Python – How to use MySQLdb when MySQL Isn’t Installed Locally
It turns out there’s a new MySQL connection library called MySQL Connector.
I installed it and then I just imported that into my script and everything else seemed to work normally. At least for my simply import script.
import mysql.connector as MySQLdb
I believe this library is designed for those who want to connect to MySQL on another server. It doesn’t seem to require any MySQL libraries to be installed.
When I tried to install mySQLdb it complained with the following message. I’m guessing the problem was that it requires MySQL to be installed:
File "/Users/pinerog/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
if mySQLdb is written properly/has its dependencies correctly, it should only require the mysql libraries. On my Ubuntu box, the dependencies (other than the standard python and libc) are:
libmysqlclient16 (>= 5.1.21-1)
So, no need for the server to be installed.
PyMySQL is what you are looking for. I have used a few times it does not require the mysql libs it is a pure python module for accessing mysql
Some more shameless self-promotion for PyMySQL here. Let me know if you need help getting it going!
Pete