Home>Article>Backend Development> PHP code cannot connect to mysql
1. Get the current mysql.default_socket, mysqli.default_socket, pdo_mysql.default_socket configuration information
2. Get the MySQL socket path
Through the console Enter MySQL, enter the command: STATUS, and find the UNIX socket value.
3. Compare mysql.default_socket, mysqli.default_socket, pdo_mysql.default_socket and MySQL UNIX socket. It is found that they are different. This is the reason for the mysql_connect(); warning: There is a problem with PHP configuration mysql.
4. Reconfigure PHP, open php.ini and modify the values of mysql.default_socket, mysqli.default_socket, and pdo_mysql.default_socket to:/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
5. Restart nginx or apache
Recommended tutorial:PHP video tutorial
The above is the detailed content of PHP code cannot connect to mysql. For more information, please follow other related articles on the PHP Chinese website!