Home  >  Article  >  Backend Development  >  PHP code cannot connect to mysql

PHP code cannot connect to mysql

王林
王林Original
2019-10-11 17:45:172719browse

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!

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
Previous article:php error shieldNext article:php error shield