Methods to solve the problem that PHP cannot connect to MySQL: 1. Open the php.ini configuration file; 2. Modify the configuration [pdo_mysql.default_socket=/tmp/mysql.sock]; 3. Restart nginx or apache.
Cause analysis:
There is a problem with PHP configuring mysql
(Learning video recommendation: java video tutorial)
Solution:
Reconfigure PHP
Specific steps:
Open the php.ini file and modify mysql.default_socket, mysqli.default_socket, The value of pdo_mysql.default_socket is: /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket=/tmp/mysql.sock mysqli.default_socket=/tmp/mysql.sock
Or modify the socket of my.cnf:
[client] socket=/tmp/mysql.sock [mysqld] socket=/tmp/mysql.sock
Then restart nginx or apache.
Related recommendations: php training
The above is the detailed content of How to solve the problem that php cannot connect to mysql. For more information, please follow other related articles on the PHP Chinese website!