在Mysql下有时候会出现mysql.sock位置错误,导致无法链接数据库。
mac下报错的时候:
首先修改my.cnf
位置在/etc/my.cnf下,假如没有的话,去/usr/locate/mysql版本/my.cnf下修改,然后复制到/etc下。
修改为如下:
[client] socket = /tmp/mysql.sock [mysqld] socket = /tmp/mysql.sock
没有[client]的话,自己添加~
然后重启mysql服务,打开mysql看看位置变了没~用,status查看
mysql Ver 14.14 Distrib 5.6.17, for osx10.7 (x86_64) using EditLine wrapper Connection id: 24 Current database: Current user: [email protected] SSL: Not in use Current pager: less Using outfile: '' Using delimiter: ; Server version: 5.6.17 MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 15 min 51 sec
然后修改php.ini(位置为/etc/php.ini)没有的话,copy一个php.ini.default
在:
pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock
这三个全部修改好~
然后
sudo apachectl stop sudo apachectl start
就可以了~
看phpinfo()下mysql.sock是否变了~
时间: 2024-12-27 04:24:59