【数据库】Mysql 连接相关

Mysql 速查笔记

一、连接

查看当前所有连接的详细

mysqladmin -h xxxx -uroot -p1234 processlist

或 进入Mysql

# 返回的Time字段 单位是秒
show full processlist;

查看当前连接数(Threads就是连接数)

mysqladmin  -h xxxx -uroot -p1234 status

或 进入Mysql

# 
status;
# Threads_connected 是已打开的连接
show status like 'Threads%';

查看指定Host的连接


杀死连接

kill 657

杀死指定用户的连接

mysqladmin -uroot -p1234 processlist|awk -F "|" '{if($3 == "Mike")print $2}'|xargs -n 1 mysqladmin -uroot -p kill

通过进入Mysql杀死

mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';
+------------------------+
| concat('KILL ',id,';') 
+------------------------+
| KILL 3101;             
| KILL 2946;             
+------------------------+
2 rows in set (0.00 sec)
 
mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)
 
mysql>source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)

查看Mysql最大连接数

show variables like 'max_connections';

修改Mysql最大连接数

一、当前进程内修改, 重启失效

set global max_connections=1000;

二、通过文件修改 #vi /etc/my.cnf,重启仍然有效

set-variable=max_user_connections=30 #这个就是单用户的连接数
set-variable=max_connections=800 #这个是全局的限制连接数
posted @ 2019-05-31 18:07  加州水果  阅读(143)  评论(0编辑  收藏  举报