mysql could not connect to the problem location and repair process sharing

  • 2020-05-15 02:21:34
  • OfStack

The positioning results are as follows:

Customer environment:
windows server 2003 r2 standard edition sp2
mysql Ver 14.12 Distrib 5.0.18, for Win32 (ia32)
apache 2.2
rising
webshield client 1.08

The problem has recurred. It can be optimized, and it is not certain that webshield is the cause.

Built environment:
windows server 2003 r2 standard edition sp2
mysql 5.0.18 for win32
apache-2.2.21-win32-x86-no_ssl
php-5.2.17-win32-vc6-x86
Rising 23.00.50.25

Some problems encountered in the process of setting up the environment:

When downloading apache and php, please note that apache matches php.

a) PHP5.3 is available in VC6 and VC9 versions. VC6 should be selected. Here's why:

i.VC6 is compiled using the Visual Studio 6 compiler. If your PHP is built using Apache, then choose VC6.
ii. VC9 is compiled using the Visual Studio 2008 compiler. If your PHP is built using IIS, then you choose VC9.

b) Thread Safe and Non Thread Safe versions of PHP5.3. The Apache no_ssl version should match the php Thread Safe version. If it is used with Non Thread Safe, apache startup error: "Apache is running threaded MPM,but your threaded apache 2.2 apache 2.2 apache 2.2 compiled to be threadsafe You need recompile recompile PHP."

i.Thread Safe is thread safe, and thread (Thread) security checks are performed to prevent system resources from being exhausted by starting a new thread of CGI execution with new requirements. The execution mode of ISAPI is in the form of DLL dynamic library, which can be executed after being requested by the user. It will not disappear immediately after processing one user request, so thread safety check is needed to improve the execution efficiency of the program. Therefore, if ISAPI is used to execute PHP, Thread Safe version is recommended.
ii.Non Thread Safe is non-thread safe and does not perform thread (Thread) security checks at execution time. The execution mode of FastCGI is performed by a single thread, so there is no need for thread safety check, and the execution efficiency can be improved by removing the protection of thread safety check. Therefore, if FastCGI is used to execute PHP, it is recommended to select Non Thread Safe version.
Note the correct configuration of apache for the site and PHP. Pay special attention to the configuration file LoadModule PHPIniDir, DocumentRoot, ServerRoot, Directory, DirectoryIndex, AddType application/x - httpd - php configuration, etc
After the installation of mysql (administrator account password: admin/admin), the connection to the database using admin in the PHP code failed, and cmd executed mysql and u root-p to enable root to connect to the database normally using root.

Problem recurrence:

Maximum execution time limit for PHP.

a) the maximum execution time of php is 30 seconds by default, after which it is aborted and the connection with mysql is broken.
b) try to increase this value, modify the php.ini configuration file in the php directory, and change max_execution_time = 30 to max_execution_time = 300. If set to 0, there is no limit to the maximum execution time of PHP.
c) avoids the failure of the mysql connection due to the maximum execution time limit.

The website was unable to connect due to the high traffic.

a) wrote php script to test mysql, and found that when mysql was frequently connected/disconnected, mysql quickly failed to connect (error code: 10048). When all connections were aborted, mysql returned to normal after 2 minutes. If the connection is not stopped, mysql1 cannot be connected.
b) tries to optimize from two aspects:
Modify the windows registry key TcpTimedWaitDelay to 30 (default is 240 seconds) and reduce the value of this entry to allow TCP/IP to release closed connections faster and provide more resources for new connections.
Modify the windows registry key MaxUserPort to 53768 (this value represents the maximum number of ports to be used when requesting any available user port from the system, TCP/IP can specify the highest possible number, the default value is 5000) to process more requests.

c) after the registry key modification test, mysql situation is greatly improved: mysql connection errors are greatly reduced, the ability to recover after errors is greatly improved.

For the above two cases, webshield 1.08 installed and webshield 1.08 not installed were tested respectively, and the test results of both cases were 1 sample.

Optimization:

Modification of max_execution_time:
Open the php.ini file in the php directory, find the line max_execution_time = 30, and change 30 to the desired number.
Modification of TcpTimedWaitDelay and MaxUserPort:


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"TcpTimedWaitDelay"=dword:0000001e
"MaxUserPort"=dword:00008000


Related articles: