Recently, a strange problem occurred to a friend's server. After two weeks, the problem was not solved. With the unremitting efforts of Brother, he finally solved the problem. Send it to your friends.
Problem: the php program can only connect to mysql using localhost, but cannot use 127.0.0.1
System Environment: centos5.5 64-bit mysql 5.0.77 php 5.2.17
The process for solving the problem is as follows:
1. According to the error message "Warning: mysql_connect () [function. mysql-connect]: Can't connect to MySQL server on '100. 0.0.1 '"use google to search for mysql_connect. Some people say that the function mysql_connect may be disabled. Other Connections cannot be used.
2. You can use google to search for mysql to connect with localhost instead of 127.0.0.1. The solution is as follows:
Modify the my. cnf file, remove skip_networking, bind_address = 127.0.0.1, and restart mysql.
For permission issues, grant all privileges on *. * to 'root' @ '127. 0.0.1 'identified by 'Password'; then flush privileges; the fault persists.
Modify the/etc/hosts file and add the 127.0.0.1 localhost item. The fault persists.
3. Check the apache error log. Only the log information such as the file does not exist is recorded, and no project related to accessing the mysql DATA connection file is found.
4. Check mysql logs and no related connection items are found.
5. Check the system log/var/log/messages. Clear echo "">/val/log/messages and access the data connection test file. The following information is found:
Nov 30 10:18:49 localhost setroubleshoot: SELinux is blocking the http daemon from connecting to network port 3306 For complete SELinux messages. run sealert-l a214e214-c710-4c84-9eb
2-000064f4b27de
The result is obvious. It is the fault of selinux. Close selinux and test "/usr/sbin/setenforce 0" to immediately disable SELINUX database connection. Everything is normal.
Finally, we come to the conclusion that selinux must be disabled when installing the server. The method is as follows:
How to disable SeLinux
1. Close SElinux quickly and use the following command:
/Usr/sbin/setenforce 0 Immediately disable SELINUX
/Usr/sbin/setenforce 1 enable SELINUX immediately
2. Add it to the default startup of the system.
Echo "/usr/sbin/setenforce 0">/etc/rc. local
3. You can edit the configuration file for the same purpose.
Vi/etc/selinux/conf
Set SELINUX = disabled
Featured here: http://www.waitalone.cn/http://www.waitalone.cn/post/mysqlselinux.html