How to solve the problem that php cannot connect to mysql

王林
Release: 2023-03-07 13:16:01
Original
3982 people have browsed it

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

Or modify the socket of my.cnf:

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!