我写了一个脚本处理消息队列,执行一段时间后,会产生大量 mysql 连接,请问如何关闭 client.query 产生的连接?
这个......
client = Mysql2::Client.new (:host => "localhost", :username => "root")
client.query(".....")
client.close
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)