Slow problem resolution for connecting to local MySQL under Windows 7/8

Source: Internet
Author: User
Problem analysis
Considering that it might be a program performance issue, I used the Xdebug performance Log function output program to run the log and found that the connection to MySQL function time actually used nearly 95% of the execution time.
The confirmation is MySQL performance problem, consider is the MySQL domain name back check function influence speed, let me disappointed is, in My.ini inside the closed domain name back check after the problem still exists.
Baffled when I had the whim to change the address of the server in the code from localhost to 127.0.0.1, the magical 1-second delay actually disappeared.
Switch to IP after incredibly good, is localhost exist what strange? Open cmd, enter ping localhost,ping output of the results I am very surprised:
Yes, localhost came out of the IPv6 address:: 1, then the reason for the second delay is also very easy to understand, using the localhost connection, the program resolved the address is IPv6 address:: 1, and then to try to connect to monitor this address of MySQL, And it is obvious that MySQL is listening to the IPv4 address 127.0.0.1, IPv6 does not even timeout will then go to connect IPv4 address 127.0.0.1, which is the reason for this 1-second delay.
Open the Hosts file for Windows and you will see the following comments
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
#:: 1 localhost
Solving method
Programme 1. Use 127.0.0.1 instead of localhost to connect to MySQL.
Programme 2. The edit Hosts file forces 127.0.0.1 to bind to localhost.

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.