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;
QQ:328864113 微信:wuhg2008
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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