1. 程式人生 > 其它 >mysql一些不常用操作

mysql一些不常用操作

技術標籤:mysql

①查詢並修改非innodb引擎為innodb引擎

select  concat('alter table ',table_schema,'.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';

在需要備份資料庫裡面的資料時,我們需要知道資料庫佔用了多少磁碟大小,可以通過一些sql語句查詢到整個資料庫的容量,也可以單獨查看錶所佔容量。

1.要查詢表所佔的容量,就是把表的資料和索引加起來就可以了

select TABLE_SCHEMA,(sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024/1024 AS 'size_g' from information_schema.tables where TABLE_SCHEMA NOT IN ('information_schema','mysql','performance_schema')  group by TABLE_SCHEMA;

2.查詢所有的資料大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables; -- 查詢所有的資料大小

3.查詢某個表的資料

select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from tables where table_schema='test' AND table_name='USER';

參考文件:mysql騷操作