Why the MySQL database connection failed frequently

Source: Internet
Author: User
Tags connection pooling connect mysql mysql database

Connection MySQL database failed frequently, what is the main cause? A year ago, I developed a Web site, rented Linux under the Php+mysql virtual space, has been working normally.

Nearly half a year, but frequent connection database failure error (a week 1~2 times), need to find space to restart the MySQL service only line:

Warning:mysql_connect (): Can 't connect to MySQL server on 'xx.xx.xx.xx ' (4) in/www/users/1b2g.com/xxxx.php on line xxxx

Looking for a space business to complain, the space business said it is my own problem, said that the other site with the host no similar problems.

On the internet search, it seems that some netizens say, operation database can not use mysql_connect () and mysql_close () switch. According to the instructions in the text, the mysql_connect () changed to Mysql_pconnect (), seems to be normal for half a month time. But this half month just because Baidu adjusts, my website traffic drops. These 2 days, the flow of recovery, the problem reappeared, and is no longer a 1-week 1~2, is appearing every day:

Warning:mysql_pconnect (): Can 't connect to MySQL server on 'xx.xx.xx.xx ' (4) in/www/users/1b2g.com/xxxx.php on line xxxx

Especially today, the restart is useless, and bad, and can not contact customer service, anxious to die.

Please help to find out, in the end what is the reason? Is it related to flow size? How to solve, thank you!

answer : For this question, there was a suggestion: optimize the program, do not have too many queries per page. Especially the circulation body inside, try not to have the inquiry again, otherwise it is easy to jam. You should consider using connection pooling

But the questioner has another problem: I have minimized the number of database connections per page.

At the beginning of the first time there is a number of links to a page is more (because the beginning for code reuse, using an IFRAME nesting), and then optimized 1 pages have been reduced to 4; other general 1~2.

Yesterday I had dropped all the connections to 2 below, with only 1 connections for the most visited pages (80% of the total number of visits).

But the problem came up at noon today.

In view of the phenomenon, 'xx.xx.xx.xx ' should you use domain name or IP as host name, so once the DNS or gateway problems, will not connect the local port, we recommend that you use localhost as the host name. LocalHost will also automatically use the pipe to connect the computer when the socket is not supported, and no connection problems will occur.

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.