'Mysql Database cant connect using "loclhost" But Can Connect using "127.0.0.1" Centos 7 (Cloudlinux)
My OS: Centos 7 + CLOUDLINUX 7.7 When I Try To Login Mysql From Server
[root@server3 ~]# Mysql -u root -h localhost -P 3306 Working ok
[root@server3 ~]# Mysql -u root -h 127.0.0.1 -P 3306 Working Ok
But When I Use localhost on Hosted Domain "xyz.com" In there DB Host = "localhost" It Not Connect, When I Change It to DB Host = "127.0.0.1" It Connect to Database
[root@server3 ~]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost localhost6.localdomain6 localhost6
[root@server3 ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.056 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.079 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.064 ms
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
any Idea For Fix?
Solution 1:[1]
MySQL connects over TCP/IP when using IP address (127.0.0.1), and uses socket file when used localhost. In your situation, I suppose you have mysql.sock in some special location and it is not available from CageFS inside. While /var/lib/mysql/
is being used by default.
If so - please add that directory to /etc/cagefs/cagefs.mp
file then run cagefsctl --remount-all
.
And Problem Fix
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Saeed |