7

I'm attempting to use mysql after only having worked with sqlite in the past.

I've installed XAMPP on Linux (ubuntu) and have mysql up and running fine (seems like that with phpMyadmin at least). However, I'm having trouble getting the MySQLdb (the python lib) working {installed this using apt}. to be exact:


>>> 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'm guessing

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

means its expecting some sort of local installation (i.e. not within XAMPP), but I can't figure out how to go about modding this to get it to work with the XAMMP flavor of mysql.

Help is much appreciated!

3 Answers 3

5

For the record (and thanks to a pointer from Igancio), I found that the below works (terrible I didn't think of this before):

db=MySQLdb.connect(
   user="root"
  ,passwd=""
  ,db="my_db"
  ,unix_socket="/opt/lampp/var/mysql/mysql.sock")
Sign up to request clarification or add additional context in comments.

Comments

1

It means that you didn't start the MySQL server, or it's configured to not use a domain socket.

Comments

0

Have the same issue using and look for your SQL configuration file my.cnf.

# 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 socket as 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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.