Home > Database > Mysql Tutorial > php连接mysql失败但通过mysql命令正常的解决方法

php连接mysql失败但通过mysql命令正常的解决方法

WBOY
Release: 2016-06-07 16:39:51
Original
1101 people have browsed it

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

故障状况:php网站连接mysql失败,但在命令行下通过mysql命令可登录并正常操作。

解决方案:

、命令行下登录mysql,执行以下命令:

showvariableslikesocket;

执行后会得到类似于如下回显:

Variable_namenbsp;nbsp;nbsp;nbsp;Value
socketnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;homemysqldatamysqlsock

2、编辑phpini,找到mysqldefault_socket配置项,默认一般是空值(使用编辑Mysql时设置的sock路径),将此项添加值为上面回显中的homemysqldatamysqlsock

;DefaultsocketnameforlocalMySQLconnectsnbsp;Ifemptyusesthebuiltin
;MySQLdefaults
mysqldefault_socket=homemysqldatamysqlsock

3、重启php。

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template