Home >Backend Development >PHP Problem >What should I do if php cannot access mysql?
Solution to the problem that php cannot access mysql: 1. Enter mysql through the console, execute the STATUS command, and find the value of the UNIX socket; 2. Open the php.ini configuration file and modify the value of mysql.default_socket; 3. Restart nginx or apache.
First enter MySQL through the console, enter the command: STATUS to find the value of the UNIX socket;
(Recommended tutorial: php Graphic tutorial)
Then open the php.ini configuration file and modify the values of mysql.default_socket, mysqli.default_socket, and pdo_mysql.default_socket to: /tmp/mysql .sock (value of UNIX socket)
pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket=/tmp/mysql.sock mysqli.default_socket=/tmp/mysql.sock
(Video tutorial recommendation: php video tutorial)
Or modify the socket of my.cnf:
[client] socket=/tmp/mysql.sock [mysqld] socket=/tmp/mysql.sock
Finally restart nginx or apache.
The above is the detailed content of What should I do if php cannot access mysql?. For more information, please follow other related articles on the PHP Chinese website!