简体   繁体   中英

MySQL connections not closing

I have a web application running on Tomcat7 that connects to MySQL 5.5.

I have two servers running the identical code:

  • Ubuntu

  • Red Hat

The Ubuntu one runs fine maintaining a steady 8-16 connections, but the Red Hat one leaks connections and the connection count grows, never going down. The server eventually resets ~152 connections.

The code to close the connection is getting called:

try {
    conn.close();           
} catch (SQLException e) {
    exceptionController.logException(this.getClass().getSimpleName(), "finalize Db", e.getMessage(), false);
}finally{
    conn = null;
}

All connections to MySQL are from this app.

Why the difference in behavior? Are there configuration settings that I should be considering - like closing sleeping connections setting ?

Ubuntu Server Status:

在此输入图像描述

Red Hat Server Status:

MySQLWorkbench服务器状态屏幕

Partial screen of the connection list: MySQLWorkbench服务器连接列表

I found this post , which appears to have slowed o/s connections, but they still are creeping up.

EDIT

Research is pointing to the connections not closing properly. Why would the connections close in one environment but not another?

I have edited my.cnf with the following setting:

wait_timeout=30

However, client connections are sleeping and never getting killed. The server has been restarted with the new setting in place.

What am I not understanding?

I found the solution. XP on SO Database Administrators .

RedHat has its own mysql folders:

[root@localhost ~]# locate my.cnf
/etc/my.cnf
/opt/rh/mysql55/root/etc/my.cnf

It was a configuration issue and my config file was not being used!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM