Reproduced: mysql MySql database connection is automatically disconnected connection problems automatically disconnect idle 8 hours caused

Transfer: https://www.cnblogs.com/ay-a/p/10520425.html

MySql idle connection is automatically disconnected problem caused 8 hours

 

I. Description of the problem

Recently encountered a strange problem MySql database, historical data at night several times a day before also normal storage, the next morning to see real-time data storage as normal, historical data is not stored. For a long time I did not find the problem. Later careful thought, a change in the historical data set was stored, the data is not been the same, it has not write data to the database, resulting in long MySql connections do not automatically disconnected. Then Baidu a bit length Mysql valid idle connections, a look at say 8 hours is automatically disconnected. Ah, feeling a little bit, it should be is the reason.

Second, Troubleshooting

According to the information found in MySql View has two parameters, the effective duration can be set idle connection, respectively, interactive_timeoutand wait_timeoutmay be provided in the mysql configuration file. According to this, the investigation can be carried out.

  1. Use the show variables like '%timeout%';command to query the values of the above two parameters, a check is 28800 (in seconds, just 8 hours).
  2. Mysql modify the configuration file interactive_timeoutand wait_timeoutare 100, 100 seconds without using so connected automatically closed.
  3. Mysql restart the service to start inserting data into the database, intermediate pause 3 minutes (to ensure that an idle connection has been disconnected), you can use the show status like 'Threads%'command to view the current number of connections, the query result Threads_connectedis the number of current connections.
  4. Continue inserting data into mysql, really did not look at the data on a storage problem successfully reproduce and find out why.

Third, to solve the problem

  1. See the code data storage section, the code found there to disconnect and reconnect to do, but judges that the connection is valid partial write a problem, there is no check mysql_queryreturn value, the data is stored when no failure log.
  2. Modify the code, automatically reconnect the disconnected, check mysql_querythe log and generating a return value, so that each database operation result has been recorded. Note: mysql c / c ++ API  mysql_queryreturns 0 for a successful operation, non-zero for the operation failed.

I. Description of the problem

Recently encountered a strange problem MySql database, historical data at night several times a day before also normal storage, the next morning to see real-time data storage as normal, historical data is not stored. For a long time I did not find the problem. Later careful thought, a change in the historical data set was stored, the data is not been the same, it has not write data to the database, resulting in long MySql connections do not automatically disconnected. Then Baidu a bit length Mysql valid idle connections, a look at say 8 hours is automatically disconnected. Ah, feeling a little bit, it should be is the reason.

Second, Troubleshooting

According to the information found in MySql View has two parameters, the effective duration can be set idle connection, respectively, interactive_timeoutand wait_timeoutmay be provided in the mysql configuration file. According to this, the investigation can be carried out.

  1. Use the show variables like '%timeout%';command to query the values of the above two parameters, a check is 28800 (in seconds, just 8 hours).
  2. Mysql modify the configuration file interactive_timeoutand wait_timeoutare 100, 100 seconds without using so connected automatically closed.
  3. Mysql restart the service to start inserting data into the database, intermediate pause 3 minutes (to ensure that an idle connection has been disconnected), you can use the show status like 'Threads%'command to view the current number of connections, the query result Threads_connectedis the number of current connections.
  4. Continue inserting data into mysql, really did not look at the data on a storage problem successfully reproduce and find out why.

Third, to solve the problem

  1. See the code data storage section, the code found there to disconnect and reconnect to do, but judges that the connection is valid partial write a problem, there is no check mysql_queryreturn value, the data is stored when no failure log.
  2. Modify the code, automatically reconnect the disconnected, check mysql_querythe log and generating a return value, so that each database operation result has been recorded. Note: mysql c / c ++ API  mysql_queryreturns 0 for a successful operation, non-zero for the operation failed.

Guess you like

Origin www.cnblogs.com/yaohuimo/p/11525321.html