1,數(shù)據(jù)表
1)schemata表 :mysql所有數(shù)據(jù)庫的信息,
show databases; 命令取的是shema_name列。
select * from information_schema.schemata;
2)tables表 :mysql所有的表信息,show tables from test_db;命令根據(jù)table_schema列取table_name
select * from information_schema.tables where table_schema = "information_schema";
3)columns表:mysql所有列的信息,show columns from schemaname.tablename;底層取自該表
select column_name from columns where table_schema = "information_schema" and table_name = "columns";
4)statistics表:mysql所有索引的信息,show index from shemaname.tablename;命令底層取自statistics表
select * from information_schema.statistics limit 1;
5)triggers表:mysql所有的觸發(fā)器。如使用pt-online-schema-change修改表結(jié)構(gòu)時,使用觸發(fā)器往影子表更新。如果手動刪除了影子表,觸發(fā)器不刪除,則會產(chǎn)生故障。
6)views表:mysql所有的視圖。
7)user_privileges表:mysql所有用戶權(quán)限。用戶表:mysql.user,權(quán)限表information_schema.user_privileges
2,相關(guān)使用
1)增加用戶與授權(quán)
image.png
2)分庫分表時,拼接sql
select concat(table_schema,'.',table_name) from information_schema.tables where table_schema like '%_order_%';
3)根據(jù)tables表的data_length,index_length(單位是字節(jié))計(jì)算庫大小、表大小、索引大小。
如: 查看information_schema庫的大小select sum(data_length + index_length)/1024/1024 from information_schema.tables where table_schema = "information_schema";
如:查看指定表則增加and table_name = ""
4)使用pt_online_schema_change,影子表不存在報(bào)錯時,檢查traggers表。
5)查看表的最后更新時間
ls -lahtr /usr/local/mysql/data/my_order_local | grep ibd
-t:Sort by time modified 默認(rèn)升序
-r:Reverse the order 順序反轉(zhuǎn)
