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

PHP code cannot connect to mysql

王林
Release: 2023-04-07 14:48:02
Original
2750 people have browsed it

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

Or modify the socket of my.cnf:

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

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!

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