Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble installing MySQLdb for second version of Python

The context: I'm working on some Python scripts on an Ubuntu server. I need to use some code written in Python 2.7 but our server has Python 2.5. We installed 2.7 as a second instance of Python so we wouldn't break anything reliant on 2.5. Now I need to install the MySQLdb package. I assume I can't do this the easy way by running apt-get install python-mysqldb because it will likely just reinstall to python 2.5, so I am just trying to install it manually.

The Problem: In the MySQL-python-1.2.3 directory I try to run python2.7 setup.py build and get an error that states:

sh: /etc/mysql/my.cnf: Permission denied

along with a Traceback that says setup.py couldn't find the file.

Note that the setup.py script looks for a mysql_config file in the $PATH directories by default, but the mysql config file for our server is /etc/mysql/my.cnf, so I changed the package's site.cfg file to match. I checked the permissions for the file, which are -rw-r--r--. I tried running the script as root and got the same error.

Any suggestions?

like image 271
Joshua Gomez Avatar asked Apr 18 '26 06:04

Joshua Gomez


1 Answers

As far as I'm aware, there is a very significant difference between "mysql_config" and "my.cnf".

  • "mysql_config" is usually located in the "bin" folder of your MySQL install and when executed, spits out various filesystem location information about your install.

  • "my.cnf" is a configuration script used by MySQL itself.

In short, when the script asks for "mysql_config", it should be taken to literally mean the executable file with a name of "mysql_config" and not the textual configuration file you're feeding it. MYSQLdb needs the "mysql_config" file so that it knows which libraries to use. That's it. It does not read your MySQL configuration directly.

The errors you are experiencing can be put down to;

  1. It's trying to open the wrong file and running into permission trouble.

  2. Even after it has tried to open that file, it still can't find the "mysql_config" file.

From here, you need to locate your MySQL installation's "bin" folder and check it contains "mysql_config". Then you can edit the folder path into the "site.cnf" file and you should be good to go.

like image 75
Michael Stubbs Avatar answered Apr 20 '26 23:04

Michael Stubbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!