0

几分钟后,我不断失去我的 MySQL 连接。在我尝试连接之前,我在日志中看不到任何错误。

我很高兴发布任何有助于调试的设置,请告诉我您需要查看的内容。

上下文.xml:

<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"
        initialSize="10" maxActive="50" maxIdle="20" maxWait="60000"
        driverClassName="com.mysql.jdbc.Driver"
        poolPreparedStatements="true"
        username="orbeon"
        password="pw"
        url="jdbc:mysql://localhost:3306/orbeon"/>

我的.cnf:

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock


[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]


user = mysql
pid-file  = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
skip-name-resolve

bind-address            = 0.0.0.0


key-buffer            = 256M
thread_stack          = 256K
thread_cache_size     = 8
max_allowed_packet    = 16M
max_connections       = 200
myisam-recover        = BACKUP
wait_timeout          = 180
net_read_timeout      = 30
net_write_timeout     = 30
back_log              = 128
table_cache           = 128
max_heap_table_size   = 32M
lower_case_table_names = 0


query_cache_limit           = 1M
query_cache_size      = 16M



log_error             = /var/log/mysql/error.log

log_slow_queries            = /var/log/mysql/slow.log
long-query-time       = 5
log-queries-not-using-indexes



[mysqldump]
quick
quote-names
max_allowed_packet    = 16M

[mysql]

[isamchk]
key-buffer            = 256M
max_allowed_packet    = 16M

!includedir /etc/mysql/conf.d/
4

2 回答 2

1

尝试将以下两个属性添加到现有<Resource>的 MySQL 中。有了这些,Tomcat 中的连接池将在从池中获取连接后检查连接是否仍然可用。

validationQuery="select 1 from dual"
testOnBorrow="true"

所以你<Resource>应该看起来像(当然有适当的用户名、密码和服务器):

<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"
    initialSize="3" maxActive="10" maxIdle="20" maxWait="30000"
    driverClassName="com.mysql.jdbc.Driver"
    poolPreparedStatements="true"
    validationQuery="select 1 from dual"
    testOnBorrow="true"
    username="orbeon"
    password="orbeon"
    url="jdbc:mysql://localhost:3306/orbeon?useUnicode=true&amp;characterEncoding=UTF8"/>
于 2013-05-06T18:06:28.897 回答
1

为什么你的 wait_timeout 设置这么低???

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout

于 2013-05-06T21:45:06.417 回答