mysql的cpu飙升原因及处理

 Mysql 批量杀死进程

正常情况下kill id,即可,但是有时候某一异常连接特别多的时候如此操作会让人抓狂,下面记录下小方法:

use information_schema;

select concat('kill ',id,';') from processlist where host like '192.168.0.1%' into outfile '/tmp/kill.sql';
        函数                                          字段        ip地址                  
source /tmp/kill.sql

 ###################################################

1.查看所有数据库容量大小

1
2
3
4
5
6
7
8
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

2.查看所有数据库各表容量大小

1
2
3
4
5
6
7
8
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
order by data_length desc, index_length desc;
 

3.查看指定数据库容量大小

例:查看mysql库容量大小

1
2
3
4
5
6
7
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
from information_schema.tables
where table_schema='mysql';

  

4.查看指定数据库各表容量大小

例:查看mysql库各表容量大小

1
2
3
4
5
6
7
8
9
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema='mysql'
order by data_length desc, index_length desc;

#################################################################

Mysql 备份单表数据

DROP TABLE IF EXISTS B;
CREATE TABLE B LIKE A;
INSERT INTO B SELECT * FROM A;

Mysql 统计表的行数

# mysqlshow -uroot -p  mysql -v -v
统计mysql数据库所有表的列数和行数

select count(*) from B.t1
统计B数据库t1表的行数

Mysql 插入一个字段 id自增并设置为主键

alter table t1 ADD id INT(16) NOT NULL PRIMARY KEY AUTO_INCREMENT first;

 

 

 

 

 

 

 

posted on   五光十色  阅读(5376)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2018-10-24 openvpn配置ldap认证
2018-10-24 Samba通过Openldap统一认证
2018-10-24 openldap 资料
2018-10-24 学习openldap03
2018-10-24 学习openldap02
2018-10-24 学习openldap01
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示