django与数据库的同步终于成功了!!mark一下 DjangoMySQLSocketPHPUnix
在安装django的时候,出现错误:
connect: _mysql_exceptions.OperationalError??: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)");
客户端在连接服务端的时候,需要找到mysql.sock
请看这篇文章
http://blog.5ilinux.com/archives/2005/06/mysqlmysqlsock.html
解决应用程序调用mysql的找不到mysql.sock的问题
新的MT系统,我使用了mysql系统,一直用的很好,不过今天我偶然去使用phpmyadmin时,居然报Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'的错误。奇怪,明明mysql正常启动,但为什么phpmyadmin不能正常连接mysql,然后又直接去linux机器,本地运行mysql命令,发现mysql确实正常运行起来,看来是phpmyadmin的问题,马上去找phpmyadmin的配置文件,发现确实有设置mysql.sock文件的位置,由于安装MT的缘故,我把mysql.sock选择在/tmp/mysql.sock。修改之下,phpmyadmin正常运行,但随之我又发现我的另外一个blog系统wp也不能正常调用mysql,它也是一个php的blog,但这个程序确没地方设置mysql.sock的位置,左思右想发现php.ini有修改mysql.sock的设置,只要在这里设置了,所有的php应用就再也不报以上错误。通过以上调试总结出以下结论:
当出些类似Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'的错误时,解决方法:
1.mysql可能没正常启动,检查mysql程序
2.修改/etc/my.cnf 修改mysql.sock的位置,使之满足php或者cgi程序的需要
3.修改php.ini的mysql.sock的设置,满足所有php程序的需要
4.修改某些程序中配置文件中关于mysql.sock的设置。
我得益于这篇文章,
http://trac.turbogears.org/turbogears/wiki/SockFile
Problem ¶
I want to use turbo gears, but my machine is setup with mysql not bound to a network socket and I get the following errors when I try to connect: _mysql_exceptions.OperationalError??: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)");
Solution ¶
There is a practice of not binding MySQL to an ip address and port following the principle that "if you're not connected, you are protected." In this situation, the server has a socket file. By default TurboGears (or SQLObject and the python MySQL driver/client to be more exact) will look for the socket file in /tmp/mysql.sock. Many installations seem to use /var/lib/mysql/mysql.sock. Therefore, to get TurboGears to work, you'll need to specify the unix_socket (if on unix) param in the dburi. You can find out where your mysql socket is by looking at the file my.cnf that usually resides in /etc/my.cnf or /etc/mysql/my.cnf.
Format: sqlobject.dburi="mysql://username:password@/databasename?unix_socket=path-to-mysql.sock"
Example: I have my socket file in /var/lib/mysql/mysql.sock and I want my user foo with password bar to connect to my db test1. sqlobject.dburi="mysql:/foo:bar@/test1?unix_socket=/var/lib/mysql/mysql.sock"