Access mysql XAMPP via Python

I am trying to use mysql after working with sqlite in the past.

I installed XAMPP on linux (ubuntu) and I have mysql and it works fine (looks like with phpMyadmin atleast). However, I am having problems with MySQLdb (python lib) working, {installed this with apt}. to be precise:

>>> import MySQLdb >>> db = MySQLdb.connect(host="localhost",db="opfine") Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init_ _ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (2002, "Can't connect to local MySQL server through socket '/var /run/mysqld/mysqld.sock' (2)") 

I suppose:

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

means that he is expecting some kind of local installation (i.e. not in XAMPP), but I can’t figure out how to do this to make it work with a mysql-like tasteful hub.

help rate!

+7
python mysql
source share
3 answers

For the record (and thanks to the pointer from Igancio), I found that below works (horrible, I had not thought about this before):

 db=MySQLdb.connect(user="root",passwd="",db="my_db",unix_socket="/opt/lampp/var/mysql/mysql.sock") 
+5
source share

This means that you did not start the MySQL server or did not configure to use a domain socket.

+1
source share

Having the same problem using and looking for my.cnf SQL configuration file.

 # The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock 

and use the socket parameter as a parameter:

 mysql://read:read@localhost/phonehome?unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock 

In my case:

 app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://read:read@localhost/phonehome?unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' 
0
source share

All Articles