-1

I have a python script which is designed to add things to a MYSQL database. The error I get is this:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

I've checked the credentials of the database in the settings and they are correct and I can connect to the database via Sequel.

I installed the following packages:

apt-get -y install build-essential python-dev libxml2-dev libxslt1-dev python-pip libmysqlclient-dev
pip install -U MySQL-python

I'm not really sure how to diagnose this. Is it looking for the mysqld.sock in the right place and it isn't there, or should it instead be looking for it in a different location.

Any help or advice would be much appreciated so I can move forward.

J.Zil
  • 1,123
  • 3
  • 21
  • 29
  • any reason not to install the `python-mysqldb` package instead of building it yourself? – dawud Aug 17 '13 at 10:22
  • I'm not sure, it was from a tutorial. Are you saying I can install that as a replacement to "MySQL-python"? I don't want to run a mysql server on my server, I just want to be able to connect to it and add a schema to it – J.Zil Aug 17 '13 at 10:33
  • The title of the question says "local MySQL server", yet you say you don't want to run a MySQL server on your server. – dawud Aug 17 '13 at 14:11

1 Answers1

1

A. If mysql is running on same server, find socket file and specify it to the application:

lsof|grep mysql.sock

or connect to the server using IP, not hostname (hostname "localhost" reverts to default socket connection, instead of TCP, defaults to /var/lib/mysql/mysql.sock)

B. If mysql is running on the other server - connection parameters are not passed correctly to your script, check how it must run.

Also, some scripts may read [client] section from ~/.my.cnf

GioMac
  • 4,544
  • 4
  • 27
  • 41
  • I have the MYSQL server externally so when I run lsof|grep mysql.sock it returns nothing. I will look into option B now to make sure. – J.Zil Aug 17 '13 at 10:33
  • 1
    There is a way to change default string via ~/.my.cnf, but it's not recommended since all applications run with that user will be able to connect to this database by default, and if password is specified - they will be able to do even more than just "connect". Security. – GioMac Aug 17 '13 at 10:36
  • @JamesWillson What do you mean that you "have the MYSQL server externally"? – Michael Hampton Aug 17 '13 at 10:59
  • good question for clarification. "so when I run lsof|grep mysql.sock it returns nothing", for me keyword is "so", probably he's not running it on localhost. – GioMac Aug 17 '13 at 11:01