MySQL管理一些基礎SQL語句

來源:互聯網
上載者:User

標籤:

 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語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.