Ubuntu 10.10 上默认通过 MySQLdb Python 库访问 XAMPP
我正在尝试构建虚拟机来开发 Django 应用程序。操作系统是Ubuntu 10.10。我已经安装了大部分东西。最后一部分是让 MySQLdb 与 XAMPP 附带的 MySQL 实例一起使用。
如何让 MySQLdb 默认与 XAMPP MySQL 一起使用?
我发现了这个: Accessing a XAMPP mysql via Python
我理解那里的问题,但该解决方案对我不起作用,因为 Django 处理在幕后创建连接。我也不想为某些应用程序操作 Django。
我尝试以两种不同的方式修改 My.cnf 但它不起作用。我仍然遇到同样的错误。该错误列于此处:
Traceback (most recent call last):
File "test-mysqldb.py", line 4, in <module>
db = MySQLdb.connect( 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 将自身安装到:/opt/lampp/
我正在寻找最简单、正确的解决方案。您可以分享的任何背景信息也会有所帮助。
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.connect( 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白为什么你不只是通过 sudo apt-get install mysql-server 安装 MySQL,但你的问题的答案似乎是配置 Django 使用指定的套接字默认的地方。
从文档到
settings.DATABASES
,位于主机
:
因此,如果您只是将数据库的 HOST 设置设置为“/opt/lampp/var/mysql/mysql.sock”,它应该会找到相关的 MySQL 套接字。
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
, underHOST
: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.