mysql系統資料庫主要存儲了一些存儲MySQL服務的系統信息表。一般情況下mysql庫的表都是MYASIM引擎,除非個別情況。mysql庫的表的作用大致可以分為以下幾類: (1)授權系統表 (2)系統對象信息系統表 (3)日誌系統表 (4)伺服器端輔助系統表 (5)time zone系統表 (6) ...
mysql系統資料庫主要存儲了一些存儲MySQL服務的系統信息表。一般情況下mysql庫的表都是MYASIM引擎,除非個別情況。mysql庫的表的作用大致可以分為以下幾類: (1)授權系統表 (2)系統對象信息系統表 (3)日誌系統表 (4)伺服器端輔助系統表 (5)time zone系統表 (6)複製相關係統表 (7)optimizer相關係統表 (8)其他系統表,下麵詳細看一看 下麵詳細講: 一:授權系統表(Grant System Tables) 授權的一些表主要有以下幾個:
user: User accounts, global privileges, and other non-privilege columns. db: Database-level privileges. tables_priv: Table-level privileges. columns_priv: Column-level privileges. procs_priv: Stored procedure and function privileges. proxies_priv: Proxy-user privileges.
基本上每一個系統表都會包含有許可權列和範圍列,也就包含一些授權的主要信息表。
user表控制了用戶是否能夠連接,如果可以連接,則會指出此用戶的許可權的信息,這個表適用於實例上的所有的資料庫。 db表範圍列決定哪些用戶可以訪問哪些資料庫從哪個主機。許可權列決定允許的操作。在資料庫級別授予的許可權適用於資料庫和資料庫中的所有對象,如表和存儲程式。 tables_priv和columns_priv表控制的許可權就更為細緻了,到了表級別和列級別。 procs_priv 表適用於存儲常式(過程和函數)。在常規級別授予的許可權只適用於一個單一的過程或函數。 proxies_priv 指出那個用戶可以作為代理,或者是用戶是否有許可權給別的用戶代理許可權。 二:系統對象信息系統表 event: event的系統表,每一次系統啟動都會重新load一遍,除非指定 --skip-grant-tables參數啟動,不然都是要load的 func: 存放關於用戶定義的方法,除非指定 --skip-grant-tables參數啟動,不然每一次系統啟動都會重新load一遍。 plugin: 存放有關伺服器插件的相關信息,除非指定 --skip-grant-tables參數啟動,不然每一次系統啟動都會重新load一遍。預設的存儲引擎是INNODB proc:存放存儲過程和方法的系統表。 三:日誌系統表,一般情況下我看了看都是NULL的general_log: The general query log table. slow_log: The slow query log table.
這兩張系統表可以將慢日誌和日誌按照表格的形式存儲下來,但是相對來說帶來對性能和存儲空間的使用更大,一般生產環境我們都建議設置為外部文件。
四:伺服器端輔助系統表help_category: Information about help categories. help_keyword: Keywords associated with help topics. help_relation: Mappings between help keywords and topics. help_topic: Help topic contents.
這些表存儲了mysql幫助的基本信息,我們都可以用HELP +列 來查看具體的幫助信息。
例如: 五:time zone的相關係統表time_zone: Time zone IDs and whether they use leap seconds. time_zone_leap_second: When leap seconds occur. time_zone_name: Mappings between time zone IDs and names. time_zone_transition, time_zone_transition_type: Time zone descriptions.
設置時區用以下方式:SET GLOBAL time_zone = timezone;
可以用以下方式查看:SELECT @@global.time_zone, @@session.time_zone; 六:複製相關的表 gtid_executed: 存儲了複製執行的GTID的信息。 ndb_binlog_index: slave_master_info, slave_relay_log_info, slave_worker_info: 只有mysql作為slave的時候才會存儲相關信息 七:optimizer相關係統表 innodb_index_stats, innodb_table_stats: 顯示的是索引的信息 Table 15.3 Columns of innodb_table_statsColumn name | Description |
database_name | Database name |
table_name | Table name, partition name, or subpartition name |
last_update | A timestamp indicating the last time that InnoDB updated this row |
n_rows | The number of rows in the table |
clustered_index_size | The size of the primary index, in pages |
sum_of_other_index_sizes | The total size of other (non-primary) indexes, in pages |
Column name | Description |
database_name | Database name |
table_name | Table name, partition name, or subpartition name |
index_name | Index name |
last_update | A timestamp indicating the last time that InnoDB updated this row |
stat_name | The name of the statistic, whose value is reported in the stat_value column |
stat_value | The value of the statistic that is named in stat_name column |
sample_size | The number of pages sampled for the estimate provided in the stat_value column |
stat_description | Description of the statistic that is named in the stat_name column |
SELECT SUM(stat_value) pages, index_name, SUM(stat_value)*@@innodb_page_size size FROM mysql.innodb_index_stats WHERE table_name='t1' AND stat_name = 'size' GROUP BY index_name; SELECT index_name, stat_name, stat_value, stat_description FROM mysql.innodb_index_stats WHERE table_name like 't1'; SELECT index_name, stat_name, stat_value, stat_description FROM mysql.innodb_index_stats WHERE table_name like 't1' AND stat_name LIKE 'n_diff%';
server_cost:伺服器操作的成本估算信息
engine_cost: 指定存儲引擎的成本估算信息 FLUSH OPTIMIZER_COSTS命令可以重新開始讀取記錄信息。 八:其他的一些系統表 audit_log_filter, audit_log_user: 這兩個表提供的是mysql審計相關的信息,如果沒有安裝的話是沒有這兩個表的。 firewall_users, firewall_whitelist: 要安裝mysql企業防火牆才可以使用。 servers: 主要是 FEDERATED 引擎使用。不做介紹了。 這是一個mysql系統庫的大概介紹,感覺比較需要我們掌握的就是關於授權,系統表,日誌表,優化表和複製相關的表。後面可以看一看mysql的日誌類型等和優化相關的方面深入瞭解一下。