What should I do if php mysql cannot be accessed?

藏色散人
Release: 2023-03-13 18:14:02
Original
2954 people have browsed it

php Solution to the problem that mysql cannot connect: 1. Create a PHP file to display "phpinfo()"; 2. Get the MySQL socket path; 3. Reconfigure PHP; 4. Restart nginx or apache.

What should I do if php mysql cannot be accessed?

The operating environment of this article: Windows 7 system, PHP version 5.5.34, DELL G3 computer

What should I do if mysql cannot be accessed?

Summary of solutions when PHP cannot connect to MySQL

1. Get the current mysql.default_socket, mysqli.default_socket, pdo_mysql.default_socket configuration information

Create a PHP file and display phpinfo():

Open with browser:

On this page, find mysql .default_socket, mysqli.default_socket, pdo_mysql.default_socket information:

##2. Get the MySQL socket path

Enter MySQL through the console, enter the command: STATUS, find the UNIX socket value

#mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8Server version: 5.7.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> STATUS--------------mysql  Ver 14.14 Distrib 5.7.11, for osx10.9 (x86_64) using  EditLine wrapper

Connection id:        8Current database:    
Current user:        root@localhost
SSL:            Not in use
Current pager:        lessUsing outfile:        ‘‘
Using delimiter:    ;
Server version:        5.7.11 MySQL Community Server (GPL)
Protocol version:    10Connection:        Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /tmp/mysql.sock
Uptime:            8 days 15 hours 1 min 17 sec

Threads: 2  Questions: 21  Slow queries: 0  Opens: 114  Flush tables: 1  Open tables: 0  Queries per second avg: 0.000--------------
Copy after login

3. This When you compare mysql.default_socket, mysqli.default_socket, pdo_mysql.default_socket and MySQL UNIX socket, you find that they are different. This is the reason for the mysql_connect(); warning: There is a problem with PHP configuring mysql.

4 . Reconfigure PHP, open php.iniModify 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 my .cnf socket:

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

5. Restart nginx or apache

Recommended study: "

PHP Video Tutorial"

The above is the detailed content of What should I do if php mysql cannot be accessed?. 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