macos下php+mysql不能使用localhost连接的问题解决

因为localhost是通过socket方式来连接,而127.0.0.1则是走的TCP协议。所以需要重新设置php-mysql的配置文件

$echo "show variables" | mysql | grep "socket"
socket	/opt/local/var/run/mysql5/mysqld.sock
$vi /opt/local/var/db/php5/mysql.ini 
; Do not edit this file; it is automatically generated by MacPorts.
; Any changes you make will be lost if you upgrade or uninstall php5-mysql.
; To configure PHP, edit /opt/local/etc/php5/php.ini.
extension=mysql.so
extension=mysqli.so
extension=pdo_mysql.so

mysql.default_socket=           /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket=          /opt/local/var/run/mysql5/mysqld.sock
pdo_mysql.default_socket=       /opt/local/var/run/mysql5/mysqld.sock

设置mysql.default_socket,mysqli.default_socket,pdo_mysql.default_socket

Tags: ,

星期二, 14 8 月, 2012 服务器

Leave a Reply

1LMooBmUE153Wnd3zDryWvDyXxQudbFxDr