In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to solve the problem that mysql can not use 127.0.0.1 connection with localhost connection". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Problem: program connection mysql can only use localhost, not 127.0.0.1
System environment: centos5.5 64-bit system mysql version 5.0.77 php version 5.2.17
The following is my process of solving the problem:
1. According to the error message "Warning: mysql_connect () [function.mysql-connect]: Can't connect to MySQL server on '127.0.0.1'" use google to search for mysql_connect. Some people say that it is possible that the function mysql_connect is disabled. Using other connections, the test will not work.
2. Use google to search mysql. You can use localhost to connect, but not 127.0.0.1. As a result, the solution for most people is:
Modify the my.cnf file, remove skip_networking,bind_address=127.0.0.1, restart mysql failure remains.
Permission problem, grant all privileges on *. * to 'root'@'127.0.0.1' identified by' password'; then flush privileges; still fails.
Modify the / etc/hosts file to add 127.0.0.1 localhost entry, and the fault remains the same.
3. Check the apache error log and find that only the log information such as the non-existence of the file is recorded, and no items related to accessing the mysql data connection file are found.
4. Check the log of mysql and no related connection items are found.
5. Finally, I remembered to check the system log / var/log/messages information too much, clean it up: echo "> / val/log/messages, and then access the data connection test file. The following information was found:
Nov 30 10:18:49 localhost setroubleshoot: SE is preventing the http daemon from connecting to network port 3306 For complete SELinux messages. Run sealert-l a214e214-c710-4c84-9eb
2-12764f4b27de
As a result, it is obvious that it is selinux's fault. Turn off selinux and test "/ usr/sbin/setenforce 0 close SELINUX immediately". Everything is fine.
Finally, we come to a conclusion that when you install the server, you must shut down the selinux. Here are the methods:
How to turn off SeLinux
1. Close SElinux quickly and use the following command:
/ usr/sbin/setenforce 0 turn off SELINUX immediately
/ 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 to achieve the same goal
Vi / etc/selinux/conf
Set SELINUX=disabled
This is the end of the content of "how to solve the problem that mysql can use localhost connection but not 127.0.0.1 connection". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.