我写了一个脚本处理消息队列,执行一段时间后,会产生大量 mysql 连接,请问如何关闭 client.query 产生的连接?
这个......
client = Mysql2::Client.new (:host => "localhost", :username => "root") client.query(".....") client.close
#1 楼 @metal close 并不管用。。。
#2 楼 @perrywky
client.close nil client.query('....') Mysql2::Error: closed MySQL connection
mysql> show processlist; +----+------+-----------+--------------------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+--------------------+---------+------+-------+------------------+ | 9 | root | localhost | information_schema | Sleep | 67 | | NULL | | 10 | root | localhost | NULL | Query | 0 | init | show processlist | +----+------+-----------+--------------------+---------+------+-------+------------------+ 2 rows in set (0.00 sec) mysql> show processlist; +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 10 | root | localhost | NULL | Query | 0 | init | show processlist | +----+------+-----------+------+---------+------+-------+------------------+ 1 row in set (0.00 sec)
#3 楼 @metal 这。。难道是我今天姿势不对。。
#4 楼 @perrywky 我觉得可能出在你代码上面,这里有个例子
https://gist.github.com/caspyin/2230396
#5 楼 @metal 问题找到了,的确是我程序的问题,我在另一个方法里新建了 client 但是没有 close,方法调用结束后这个 client 也没有自动释放连接 多谢你啦!