Access XAMPP by default via MySQLdb Python lib on Ubuntu 10.10
I'm attempting to build a Virtual Machine to develop a Django application. The OS is Ubuntu 10.10. I have most everything installed. The last piece is getting MySQLdb to work with the MySQL instance that comes with XAMPP.
How can I get MySQLdb to default to work with the XAMPP MySQL?
I found this: Accessing a XAMPP mysql via Python
I understand the problem there, but the solution doesn't work for me because Django handles creating connections behind the scenes. I also don't want to be manipulating Django for some an application.
I've attempted to modify the My.cnf in two different ways but it doesn't work. I'm still getting the same error. That error is listed here:
Traceback (most recent call last):
File "test-mysqldb.py", line 4, in <module>
db = MySQLdb.connec开发者_StackOverflowt( user="root", passwd="", db="faceless001" )
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)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
XAMPP installed itself to: /opt/lampp/
I'm looking for the simplest, correct solution for this. Any background info you can share would be helpful, also.
I don't understand why you don't just install MySQL via sudo apt-get install mysql-server
, but nevertheless the answer to your question would seem to be to configure Django to use the specified socket in place of the default.
From the documentation to settings.DATABASES
, under HOST
:
If this value starts with a forward slash ('/') and you're using MySQL, MySQL will connect via a Unix socket to the specified socket.
So if you just set the HOST setting for your database to "/opt/lampp/var/mysql/mysql.sock"
it should find the relevant MySQL socket.
精彩评论