標籤:
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 DESC25 26 SELECT table_name,table_rows,create_time,update_time27 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 namestr33 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 namestr37 FROM information_schema.`COLUMNS` WHERE table_schema=‘dbname‘ AND table_name=‘tablename‘ ;38 39 10、#查看是否開啟事件40 select @@event_scheduler
MySQL管理一些基礎SQL語句