information_schema.tables視圖
desc information_schema.TABLES
TABLE_SCHEMA ---->庫名
TABLE_NAME ---->表名
ENGINE ---->引擎
TABLE_ROWS ---->表的行數
AVG_ROW_LENGTH ---->表中行的平均行(字節)
INDEX_LENGTH ---->索引的佔用空間大小(字節)
查詢整個數據庫中所有庫和所對應的表信息
select table_schema,group_concat(table_name)
from information_schema.tables
group by table_schema;
統計所有庫下的表個數
select table_schema,count(table_name)
FROM information_schema.TABLES
GROUP BY table_schema
查詢所有innodb引擎的表及所在的庫
select table_schema,table_name,ENGINE FROM information_schema.`TABLES`
WHERE engine='innodb';
統計world數據庫下每張表的磁盤空間佔用
SELECT table_name,CONCAT((TABLE_ROWS*AVG_ROW_LENGTH+INDEX_LENGTH)/1024," KB") AS size_KB
FROM information_schema.tables WHERE TABLE_SCHEMA='world';
統計所有數據庫的總的磁盤空間佔用
SELECT
TABLE_SCHEMA,
CONCAT(SUM(TABLE_ROWS*AVG_ROW_LENGTH+INDEX_LENGTH)/1024," KB") AS Total_KB
FROM information_schema.tables
GROUP BY table_schema;
mysql -uroot -p123 -e "SELECT TABLE_SCHEMA,CONCAT(SUM(TABLE_ROWS*AVG_ROW_LENGTH+INDEX_LENGTH)/1024,' KB') AS Total_KB FROM information_schema.tables GROUP BY table_schema;"
生成整個數據庫下的所有表的單獨備份語句
模板語句:
mysqldump -uroot -p123 world city >/tmp/world_city.sql
SELECT CONCAT("mysqldump -uroot -p123 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql" )
FROM information_schema.tables
WHERE table_schema NOT IN('information_schema','performance_schema','sys')
into outfile '/tmp/bak.sh' ;
CONCAT("mysqldump -uroot -p123 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql" )
show 命令
show databases; #查看所有數據庫
show tables; #查看當前庫的所有表
show tables from 庫名 #查看某個指定庫下的表
show create database 庫名 #查看建庫語句
show create table 庫名.表名 #查看建表語句
show grants for root@'localhost' #查看用戶的權限信息
show charset; #查看字符集
show collation #查看校對規則
show processlist; #查看數據庫連接情況
show index from #表的索引情況
show status #數據庫狀態查看
SHOW STATUS LIKE '%lock%'; #模糊查詢數據庫某些狀態
SHOW VARIABLES #查看所有配置信息
SHOW variables LIKE '%lock%'; #查看部分配置信息
show engines #查看支持的所有的存儲引擎
show engine innodb status\G #查看InnoDB引擎相關的狀態信息
show binary logs #列舉所有的二進制日誌
show master status #查看數據庫的日誌位置信息
show binlog evnets in #查看二進制日誌事件
show slave status \G #查看從庫狀態
SHOW RELAYLOG EVENTS #查看從庫relaylog事件信息
desc (show colums from city) #查看錶的列定義信息
mysql 官網
http://dev.mysql.com/doc/refman/5.7/en/show.html