Home >Backend Development >PHP Problem >How to solve the problem that php cannot connect to mysql

How to solve the problem that php cannot connect to mysql

王林
王林Original
2020-11-06 17:29:514076browse

Methods to solve the problem that PHP cannot connect to MySQL: 1. Open the php.ini configuration file; 2. Modify the configuration [pdo_mysql.default_socket=/tmp/mysql.sock]; 3. Restart nginx or apache.

How to solve the problem that php cannot connect to mysql

Cause analysis:

There is a problem with PHP configuring mysql

(Learning video recommendation: java video tutorial)

Solution:

Reconfigure PHP

Specific steps:

Open the php.ini file and modify mysql.default_socket, mysqli.default_socket, The value of pdo_mysql.default_socket is: /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

Then restart nginx or apache.

Related recommendations: php training

The above is the detailed content of How to solve the problem that php 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