Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to learn MySQL but wanting to host my site in cgi/python. I have XAMPP install (apache and friends) for testing my site before I move it to my VPS. I've installed python-MySQLdb but every time I try to connect to the xampp database I get this,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
>>> con = MySQLdb.connect("localhost", "root", "", "bucky")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

I've looked at several other of these questions involving the same error but they all have MySQL-server installed. I have it running out of /opt/lampp/. What would I need to do to access my MySQL server?

share|improve this question
    
- You are not going to move a XAMP installation to a VPS. XAMP has security holes and is not for actual usage; only for testing purposes. - Do I see your root password in that traceback?! - Can you connect from command line to MySQL? –  Rinzwind Jul 15 '13 at 14:06
    
o no, I was simply moving the php files over and giving my vps a different user without as many privileges. Anyways, no I cannot connect through the CLI either. –  KI4JGT Jul 15 '13 at 15:48
    
@KI4JGT What happens if you replace "localhost" with "127.0.0.1"? I think if you use 127.0.0.1 it will prefer TCP over socket connection. Also are you able to connect using mysql -u root -p? –  Salem Jul 15 '13 at 17:33
    
That worked. Thanks so much. –  KI4JGT Jul 15 '13 at 22:27
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.