Problem: The PHP program on one server cannot connect to the database via the localhost address, but can connect normally if it is set to 127.0.0.1, and can also connect to other database servers normally. The MySQL permissions are set correctly, and the database can be connected normally through the mysql command line client. Analysis: This is a typical case where the socket is not configured correctly. There are two ways to connect to a MySQL database: TCP/IP (the kind commonly understood as a port) and Unix sockets (generally called sockets or socks). In most cases, localhost can be used to represent the local machine 127.0.0.1, but when connecting to MySQL, the two cannot be mixed, and localhost and 127.0.0.1 are also set separately in the permission settings in MySQL. When set to 127.0.0.1, the system connects to the database via TCP/IP; when set to localhost, the system connects to the database via socket. Solution: First, check where the socket file of the local MySQL is. The command to check is: mysqld --verbose --help | grep socket The output shows the location of the socket file. For example, this server shows socket /var/run/mysqld/mysqld.sock Then modify the php configuration file php.ini to correspond to it. Find this one: mysql.default_socket = Generally this item is empty, change it to: mysql.default_socket = /var/run/mysqld/mysqld.sock The file queried in the previous step should be written here and set according to your situation. At this point, the PHP configuration has been modified. If it is CLI (command line) mode or CGI mode, it will take effect immediately. If it is FASTCGI mode, you need to restart the fastcgi process. The above article perfectly solves the problem that MySQL cannot connect to the database through localhost. This is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Graphical tutorial on installing CentOS 7.3 on VMWare
>>: Implementation of vscode custom vue template
question Running gdb in docker, hitting a breakpo...
What are slots? The slot directive is v-slot, whi...
Table of contents 1. Test environment 1.1 Install...
Preface For production VPS with public IP, only t...
During the crawler development process, you must ...
To query two different tables, you need to merge ...
This article shares with you the graphic tutorial...
Netease Kanyouxi official website (http://kanyoux...
This article shares the installation and configur...
Table of contents Scope Global Scope Function Sco...
Preface Creating shortcuts in Linux can open appl...
Code Sample Add a line of code in the head tag: XM...
Recently, I have done a simple study on the data ...
Table of contents 1. Configure bridging and captu...
Are you still looking for a way to enable Hyper-v...