MySQL parameter autoReconnect=true to solve 8-hour connection failure

1. Even if the autoReconnect=true parameter is added to the url when creating Mysql, once the time for this connection to access the database twice exceeds the server-side wait_timeout time limit, CommunicationsException: The last packet successfully received from the server was xxx milliseconds ago.
2. The parameters on the server side can be set with
  show global variables like 'wait_timeout';
  set global wait_timeout=10;,
  but the wait_timeout value should not be set too high.
3. A better strategy is to set the connection in the idle state Send a sql regularly to refresh the timestamp on the server. This can use the connection pool of c3p0r. http://bzhang.iteye.com/blog/321832
4. For the connection pool used in tomcat's server.xml, http: //tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html,http://commons.apache.org/dbcp/configuration.htmlA connection pool using DBCP can use
<Resource name= "jdbc/test" auth="Container" 
              type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8" 
              username="root" password="test" maxActive="500" maxIdle="10" 
              maxWait="-1" timeBetweenEvictionRunsMillis=" 10000" minEvictableIdleTimeMillis="10000" />
  4.1 Set the validationQuery, so every time you borrow (open by default), the validity of the connection will be verified through this sql, but the time will be increased.
  4.2 Set timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="10000 " Relying on the evictor thread to close the timeout connection.
  4.3 Set testWhileIdle="true" timeBetweenEvictionRunsMillis="10000" validationQuery="select 1" to use the query to detect the connection in the idle state periodically, which also refreshes the server-side time.

5. The maximum packet size of each submission
show global variables like 'max_allowed_packet';
set global max_allowed_packet=1024*1024;

6. Setting of connection parameters
  in SQLyog 6.1 Set autocommit=0 in SQLyog, so that the auto-commit of the current connection is false, and the transaction can be controlled.
  6.2 begin; transaction starts
  6.3 select * from test where 1=1 and id = 1 for update; This will lock the selected row of records, open another SQLyog, and perform the same operations as above, and it will always wait there.
  6.4 commit; commit
  6.5 rollback; rollback
  6.6 set autocommit=0; After that,
      set transaction isolation level read committed should be added ;
      so that other clients can see the committed data.
  Question:
      if set transaction isolation level read committed is not set; if two clients select the same data, one client will modify Then submit, another client does not submit the current transaction, executes select, and cannot get the data submitted by another client, I don't know what the default transaction level of SQLyog is.

7. To view the status of mysql in SQLyog, show global variables like '%lock%'; is a good method. For transaction locks (such as for update) to report Lock wait timeout exceeded, only by modifying the my.ini file innodb_lock_wait_timeout = 100; take effect.

8. Modify user password mysqladmin -u root password "new_pass" under linux

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326169039&siteId=291194637