Solve the problem that php cannot connect to the mysql database through localhost

Source: Internet
Author: User
Solve the problem that php cannot connect to the mysql (PerconaServer) database through localhost and connect to the mysql database through ip addresses such as 127.0.0.1. problem occurred when using the online generation tool on the PerconaServer website generated my. cnf configuration file. php cannot connect to the mysql database through localhost after the right-side configuration is enabled. however

Solve the problem that php cannot connect to the mysql (Percona Server) database through localhost and can connect to the mysql database through ip addresses such as 127.0.0.1. problem occurred when using the online generation tool on the official website of Percona Server to generate my. cnf configuration file. php cannot connect to the mysql database through localhost after the right-side configuration is enabled. however

Solve the problem that php cannot connect to the mysql (Percona Server) database through localhost and can connect to the mysql database through ip addresses such as 127.0.0.1.

Problem generation

The my. cnf configuration file is generated by using the online generation tool on the Percona Server website. After the right and right configurations are configured and OK is enabled, php cannot connect to the mysql database through localhost.

However, it can be connected through an IP address.

Differences between localhost and 127.0.0.1 of mysql

What does localhost use? Unix? Sock
What does 127.0.0.1 go through? Tcp

Cause Analysis

The problem that the localhost cannot be connected is that mysql is used in php by default? Unix? What does sock use? /Tmp/mysql. sock
If you have modified the sock path of mysql, you must specify it in php. ini.

Solve the problem

So: How does php connect to mysql? Localhost cannot be connected. ip addresses such as 127.0.0.1 can be connected.

1. modify the configuration in php. ini and specify the mysql. sock location.
Or
2. modify my. cnf configuration ?? /Tmp/mysql. sock

Zemanta

Original article address: solve the problem that php cannot connect to the mysql database through localhost. Thank you for sharing it with the original author.

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.