mysql 常用语句

一、查询:

truncate alerts;  #清空表数据
select
count(*) from win_cdr_trunk_201807_oneself where time_start<'2018-08-01 00:00:00'; #计算2018-08-01 00:00:00之前数据总数
select count(*) from   win_cdr201806 where start_year='2018' and start_month='06'; #计算2018-06月份数据总数



create table `insurance_pay_20201113`  like  `insurance_pay`;
insert into insurance_pay_20201113 select * from insurance_pay;

 备份数据库

mysqldump --set-gtid-purged=off  -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod win_agmonitor > win_agmonitor.sql
mysqldump --set-gtid-purged=off -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod rep_tmp_time > rep_tmp_time.sql

mysql -u root -pHaixue.*X_864.o8 ccod < win_agmonitor.sql
mysql -u root -pHaixue.*X_864.o8 ccod < rep_tmp_time.sql

mysqldump --set-gtid-purged=off  -u root -pHaixue.*X_864.o8 -h 192.168.22.204 ccod win_agmonitor > win_agmonitor.sql

 查询所有存储过程,并生成删除语句

select concat('drop procedure if exists ',b.SPECIFIC_NAME,';')as yuju from   (select  SPECIFIC_NAME  from information_schema.routines 
where routine_schema in ('0802test','0903beifen') and ROUTINE_TYPE = 'PROCEDURE') b;

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

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.查看所有数据库各表容量大小

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库容量大小

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库各表容量大小

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;

 

posted @ 2020-09-24 22:14  灬魑魅魍魉灬  阅读(111)  评论(0编辑  收藏  举报