Mysql can be connected using localhost and cannot be connected using 127.0.0.1 _ MySQL

Source: Internet
Author: User
Tags apache error log
Mysql can be connected using localhost and cannot be connected using 127.0.0.1 solution bitsCN.com

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

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.