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

What should I do if php cannot access mysql?

王林
Release: 2023-03-04 12:40:02
Original
2745 people have browsed it

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
Copy after login

(Video tutorial recommendation: php video tutorial)

Or modify the socket of my.cnf:

[client]  
socket=/tmp/mysql.sock  
  
[mysqld]  
socket=/tmp/mysql.sock
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template