mysql管理一些基础sql语句 -凯发k8官方网
凯发k8官方网
收集整理的这篇文章主要介绍了
mysql管理一些基础sql语句
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1 1、进入information_schema 数据库(存放了其他的数据库的信息)
2 use information_schema;
3
4 2、查询所有数据的大小:
5 select concat(round(sum(data_length/1024/1024),2),'mb') as data from information_schema.tables;
6
7 3、查看指定数据库的大小:
8 比如查看数据库home的大小
9 select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='home';
10 查看数据所占的空间大小 11 select concat(round(sum(data_length)/(1024*1024),2) round(sum(index_length)/(1024*1024),2),'mb') as 'db size' 12 from information_schema.`tables` where table_schema='dbname' 13 14 15 4、查看指定数据库的某个表的大小 16 比如查看数据库home中 members 表的大小 17 select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='home' and table_name='members'; 18 select concat(round(sum(data_length/1024/1024),2),'mb') as data from information_schema.tables where table_schema='dbname' and table_name='t_msg_app_new'; 19 20 5、查看指定数据库的表的大小 大到小 21 select table_name,concat(round((data_length/1024/1024),2),'mb') as data from tables where table_schema='dbname' order by data_length desc; 22 23 6、查看指定数据库表的创建时间,更新时间。 24 select table_name,create_time,update_time from information_schema.`tables` where table_schema='dbname' order by update_time desc 25 26 select table_name,table_rows,create_time,update_time 27 from information_schema.`tables` where table_schema='dbname' and table_name='tablename' order by update_time desc
28 7、查看所有存储引擎为myisam的表 29 select * from `information_schema`.`tables` where table_schema='dbname' and `engine`='myisam' 30 31 8、查询表中的所有列 32 select group_concat(column_name)as namestr 33 from information_schema.`columns` where table_name='tablename' ; 34 35 9、查询表中的所有列(拼接插入insert sql) 36 select concat('insert into ',table_name,'(',group_concat(column_name),')values()')as namestr 37 from information_schema.`columns` where table_schema='dbname' and table_name='tablename' ; 38 39 10、#查看是否开启事件 40 select @@event_scheduler
10 查看数据所占的空间大小 11 select concat(round(sum(data_length)/(1024*1024),2) round(sum(index_length)/(1024*1024),2),'mb') as 'db size' 12 from information_schema.`tables` where table_schema='dbname' 13 14 15 4、查看指定数据库的某个表的大小 16 比如查看数据库home中 members 表的大小 17 select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='home' and table_name='members'; 18 select concat(round(sum(data_length/1024/1024),2),'mb') as data from information_schema.tables where table_schema='dbname' and table_name='t_msg_app_new'; 19 20 5、查看指定数据库的表的大小 大到小 21 select table_name,concat(round((data_length/1024/1024),2),'mb') as data from tables where table_schema='dbname' order by data_length desc; 22 23 6、查看指定数据库表的创建时间,更新时间。 24 select table_name,create_time,update_time from information_schema.`tables` where table_schema='dbname' order by update_time desc 25 26 select table_name,table_rows,create_time,update_time 27 from information_schema.`tables` where table_schema='dbname' and table_name='tablename' order by update_time desc
28 7、查看所有存储引擎为myisam的表 29 select * from `information_schema`.`tables` where table_schema='dbname' and `engine`='myisam' 30 31 8、查询表中的所有列 32 select group_concat(column_name)as namestr 33 from information_schema.`columns` where table_name='tablename' ; 34 35 9、查询表中的所有列(拼接插入insert sql) 36 select concat('insert into ',table_name,'(',group_concat(column_name),')values()')as namestr 37 from information_schema.`columns` where table_schema='dbname' and table_name='tablename' ; 38 39 10、#查看是否开启事件 40 select @@event_scheduler
转载于:https://www.cnblogs.com/cyun/p/5565612.html
总结
以上是凯发k8官方网为你收集整理的mysql管理一些基础sql语句的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 记我的一次电话面试 (转)
- 下一篇: