centos cannot connect to the database using localhost

王林
Release: 2020-03-18 15:55:19
Original
3394 people have browsed it

centos cannot connect to the database using localhost

Question:

Under Centos system, use mysql database. When the host name is 127.0.0.1, the connection can be successful, but if localhost is used, the connection will fail.

Analysis:

There are two options for connecting to the mysql database.

1. TCP/IP (network connection)

TCP/IP socket connection method is a connection method provided by MySQL on any platform, and it is also the most commonly used one on the network. Way. This method establishes a network-based connection request on a TCP/IP connection. Generally, the client is on one server and the MySQL instance is on another server. The two machines are connected through the TCP/IP network

2. Unix domain socket connection (non-network connection)

In Linux and Unix environments, you can also use Unix domain socket connection. Unix domain sockets are not actually a network protocol, so they can only be used when the MySQL client and database instance are on the same server. The socket file path can be specified in the configuration file, such as -socket=/tmp/mysql.sock.

(Recommended tutorial: centos usage tutorial)

Solution:

1. Check the socket file location of the local mysql

mysqld --verbose --help | grep socket
Copy after login

2. Find a similar item in the query results

socket    /var/run/mysqld/mysqld.sock
Copy after login

3. In the php configuration file, find the following item:

mysql.default_socket =
Copy after login

4. Modify it to :

mysql.default_socket = 找到的socket路径
Copy after login

5. Save the file and restart php-fpm

Recommended related video tutorials: linux video tutorial

The above is the detailed content of centos cannot connect to the database using localhost. 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