MySQL uses localhost unable to connect problem resolution (127.0.0.1 can connect)

Source: Internet
Author: User
Tags php and php and mysql

When the probe is used for phpinfo testing after installation. The default localhost is found to be unable to connect to the MARIADB database, but can be connected through 127.0.0.1. Said it was very depressing. The first thought was: is the Hosts file problem on the Linux server.

So, echo "127.0.0.1 localhost" >>/etc/hosts && sync.


The result is still the same, localhost cannot connect 127.0.0.1 can connect.
On the internet to see a friend said is SELinux problem, but, general system installed after I have SELinux set to permissive mode. So there is further set to Disabled mode. The result is the same.
Finally found is the relationship between PHP and MySQL, we only need to modify the php.ini configuration on it.
The Mysqld.sock file address is not specified in the php.ini configuration file for the default compilation installation, and it is looked up from the default in/var/run/mysqld/mysqld.sock. While compiling the installation of the MARIADB installation of the Mysqld.sock file in the/usr/local/mysql/tmp directory. and PHP through the localhost connection MySQL is exactly the way to use the Mysqld.sock to connect. Therefore, the above problems appear in our clear antecedents.
Below we view the local Mysqld.sock file location, write it to the php.ini configuration inside OK.

The most conservative approach is to execute the sync command for data writing. Then restart the apache2 server. In general, you do not have to execute these two commands. I have used it directly and cannot do any more tests.

Related Article

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.