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.