Home  >  Article  >  Backend Development  >  What should I do if php cannot access mysql?

What should I do if php cannot access mysql?

王林
王林Original
2020-08-13 14:13:052664browse

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.

What should I do if php cannot access mysql?

First enter MySQL through the console, enter the command: STATUS to find the value of the UNIX socket;

(Recommended tutorial: php Graphic tutorial)

What should I do if php cannot access mysql?

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!

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