Home >Database >Mysql Tutorial >php连接不上mysql但mysql命令行操作正常的解决方法_MySQL

php连接不上mysql但mysql命令行操作正常的解决方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:17:42949browse

故障状况:php网站连接mysql失败,但在命令行下通过mysql命令可登录并正常操作。
解决方案:
1、命令行下登录mysql,执行以下命令:
show variables like 'socket';
执行后会得到类似于如下回显:

"Variable_name"        "Value"
"socket"                  "/home/mysql/data/mysql.sock"
2、编辑php.ini,找到mysql.default_socket配置项,默认一般是空值(使用编辑Mysql时设置的sock路径),将此项添加值为上面回显中的"/home/mysql/data/mysql.sock":

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /home/mysql/data/mysql.sock
3、重启php。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn