Components:
Prometheus
Grafana
MySQL Exporter
Prometheus
Grafana
MySQL Exporter
mysql> show variables like 'max_connections';
或者:
mysql> show variables like '%connect%';
mysql> show status like '%connect%';
mysql> show status like 'Threads_connected';
或者:
mysql> show status where variable_name = 'Threads_connected';
# vi /etc/my.cnf
添加以下内容:
......
max_connections=32000
(步骤略)
mysql> select * from information_schema.innodb_trx where trx_state='LOCK WAIT';
(补充:可以通过被锁住的表推断哪些 SQL 语句耗时较长)
mysql> show processlist
mysql> select id,user,host,state,info,time,command
from information_schema.processlist
where command !='Sleep'
order by time desc;
(
补充:
1) 这里以显示 information_schema.processlist 表里的 id、user、host、state、info、time、command 字段为例
2) 这里的 where command != ‘Sleep’ 代表排除处于睡眠状态的 SQL 语句
)
mysql> select *
from information_schema.processlist
where command != 'Sleep'
and time > 0
order by time desc
limit 10;
(
补充:
1) 这里以显示 information_schema.processlist 表里的所有字段为例
2) 这里的 where command != ‘Sleep’ 代表排除处于睡眠状态的 SQL 语句
)
mysql> select id,user,host,state,info,time,command
from information_schema.processlist
-- where db = 'eternalcenter'
where command !='Sleep'
order by time desc;
(
补充:
1) 这里以显示 information_schema.processlist 表里的 id、user、host、state、info、time、command 字段为例
2) 这里的 — where db = ‘eternalcenter’ 代表查看对 eternalcenter 库进行操作的 SQL 语句
3) 这里的 where command != ‘Sleep’ 代表排除处于睡眠状态的 SQL 语句
)
mysql> kill <SQL ID>
mysql> select concat('kill ',id,';')
from information_schema.processlist
where command ='Query'
order by time desc
limit 5;
mysql> select ID,COMMAND,INFO
from information_schema.processlist
where command ='Query'
order by time desc
;
> SHOW STATUS LIKE 'Threads_connected';
> SHOW VARIABLES LIKE 'max_connections';
> SET GLOBAL max_connections = 200;
(补充:这里以临时将数据库目前所允许的最大连接数设置为 200 为例)
> SHOW PROCESSLIST;
> SELECT * FROM performance_schema.threads;
(注意:当数据库越来越大是,全库查询的 SQL 语句执行起来会越来越慢,耗时也会越来越长。应用最终会被 SQL 语句查询的长时间拖死)
(步骤略)
(步骤略)
(步骤略)
查看 MariaDB & MySQL 用户使用的插件
# select user,plugin from mysql.user;
mysql> create user 'mingyuzhu'@'192.168.%' identified by 'mypassword';
(补充:这里以创建用户 mingyuzhu@192.168.% 并且把密码设置成 mypassword 为例)
mysql> alter user 'mingyuzhu'@'192.168.%' password expire interval 90 day;
(补充:这里以将用户 mingyuzhu@192.168.% 密码的有效期设置为 90 天为例)
mysql> grant select,insert,update,delete,drop,create on eternalcenter.* to 'mingyuzhu'@'192.168.%';
(补充:这里以给用户 mingyuzhu@192.168.% 库 eternalcenter 增、删、改、查的权限为例)
mysql> flush privileges;
mysql> drop user 'mingyuzhu'@'192.168.%';
(补充:这里以删除用户 mingyuzhu@192.168.% 为例)