MySQL管理一些基础SQL语句
生活随笔
收集整理的這篇文章主要介紹了
MySQL管理一些基础SQL语句
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1 1、進(jìn)入information_schema 數(shù)據(jù)庫(kù)(存放了其他的數(shù)據(jù)庫(kù)的信息)
2 use information_schema;
3
4 2、查詢(xún)所有數(shù)據(jù)的大小:
5 select concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables;
6
7 3、查看指定數(shù)據(jù)庫(kù)的大小:
8 比如查看數(shù)據(jù)庫(kù)home的大小
9 select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';
10 查看數(shù)據(jù)所占的空間大小 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、查看指定數(shù)據(jù)庫(kù)的某個(gè)表的大小 16 比如查看數(shù)據(jù)庫(kù)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、查看指定數(shù)據(jù)庫(kù)的表的大小 大到小 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、查看指定數(shù)據(jù)庫(kù)表的創(chuàng)建時(shí)間,更新時(shí)間。 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、查看所有存儲(chǔ)引擎為MyISAM的表 29 SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA='dbname' AND `engine`='MyISAM' 30 31 8、查詢(xún)表中的所有列 32 SELECT GROUP_CONCAT(column_name)AS namestr 33 FROM information_schema.`COLUMNS` WHERE table_name='tablename' ; 34 35 9、查詢(xún)表中的所有列(拼接插入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、#查看是否開(kāi)啟事件 40 select @@event_scheduler
10 查看數(shù)據(jù)所占的空間大小 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、查看指定數(shù)據(jù)庫(kù)的某個(gè)表的大小 16 比如查看數(shù)據(jù)庫(kù)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、查看指定數(shù)據(jù)庫(kù)的表的大小 大到小 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、查看指定數(shù)據(jù)庫(kù)表的創(chuàng)建時(shí)間,更新時(shí)間。 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、查看所有存儲(chǔ)引擎為MyISAM的表 29 SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA='dbname' AND `engine`='MyISAM' 30 31 8、查詢(xún)表中的所有列 32 SELECT GROUP_CONCAT(column_name)AS namestr 33 FROM information_schema.`COLUMNS` WHERE table_name='tablename' ; 34 35 9、查詢(xún)表中的所有列(拼接插入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、#查看是否開(kāi)啟事件 40 select @@event_scheduler
?
轉(zhuǎn)載于:https://www.cnblogs.com/cyun/p/5565612.html
總結(jié)
以上是生活随笔為你收集整理的MySQL管理一些基础SQL语句的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 记我的一次电话面试 (转)
- 下一篇: 大数据vs计算机