标签:原因 roo 原来 uptime erro lwp bash 配置 conf
出现这种错误明显就是 mysql_connect 之后忘记 mysql_close;
当大量的connect之后,就会出现Too many connections的错误,mysql默认的连接为100个,而什么情况下会出现这种错误呢?
正常的mysql_connect 之后调用 mysql_close()关闭连接
但在连接错误时,会者mysql_real_query()出现错误退出时,可能忘记mysql_close();
所以在程序return 之前一定要判断是否close(),最稳妥的方法就是在写任何函数时都只有一个出口!
./mysqladmin -uroot -p1234.com status
Uptime: 1370150 Threads: 1 (当前连接数) Questions: 79 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.000
./mysql -uroot -p1234.com -e ‘show status‘ | grep -i Threads Delayed_insert_threads 0 Slow_launch_threads 0 Threads_cached 1 Threads_connected 1 Threads_created 2 Threads_running 1 ##(当前连接数)
mysql> show status like ‘Threads%‘; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 1 | | Threads_connected | 1 | | Threads_created | 2 | | Threads_running | 1 | ###当前连接数 +-------------------+-------+ 4 rows in set (0.00 sec)
查看最大连接数
[root@xxx bin]# ./mysql -uroot -p1234.com -e ‘show variables‘ | grep max_connections max_connections 500
mysql> show global variables like ‘max_conn%‘; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 10 | | max_connections | 500 |## 最大连接数 +--------------------+-------+ 2 rows in set (0.00 sec)
[root@xxx bin]# gdb -p $(cat /data/mydata/xxx.pid) -ex "set max_connections=500" -batch [New LWP 7667] [New LWP 4816] [New LWP 341] [New LWP 338] [New LWP 337] [New LWP 336] [New LWP 335] [New LWP 331] [New LWP 330] [New LWP 329] [New LWP 328] [New LWP 327] [New LWP 326] [New LWP 325] [New LWP 324] [New LWP 323] [New LWP 322] [Thread debugging using libthread_db enabled] 0x00000035654df1b3 in poll () from /lib64/libc.so.6
mysql> show variables like ‘%pid%‘; +---------------+----------------------+ | Variable_name | Value | +---------------+----------------------+ | pid_file | /data/mydata/xxx.pid | +---------------+----------------------+ 1 row in set (0.00 sec)
修改完毕后 ,尝试重新进入数据库,并查看链接数
这种方法设置后,只是暂时的,数据库重启后,会变为原来的数值,要想永久,设置完后修改配置文件my.cnf
方法2设置新的最大连接数为200:mysql> set GLOBAL max_connections=200
显示当前运行的Query:mysql> show processlist
显示当前状态:mysql> show status
退出客户端:mysql> exit
这种方法设置后,只是暂时的,数据库重启后,会变为原来的数值,要想永久,设置完后修改配置文件my.cnf
#!/bin/bash set j=2 while true do let "j=j+1" /usr/local/mysql/bin/mysqlslap -a -c 500 -i 10 -uroot -p1234.com done
运行此脚本 ,然后导致mysql连接数过多无法连接,多试几次确定无法连接 再用gdb工具测试
标签:原因 roo 原来 uptime erro lwp bash 配置 conf
原文地址:http://www.cnblogs.com/lazyball/p/7424243.html