MySQL是一款開源的關(guān)系型數(shù)據(jù)庫(kù)系統(tǒng)。當(dāng)我們安裝了MySQL并成功啟動(dòng)之后,會(huì)發(fā)現(xiàn)有一些默認(rèn)庫(kù)已經(jīng)被創(chuàng)建。這篇文章會(huì)介紹MySQL默認(rèn)庫(kù)的種類和作用。
1. mysql庫(kù)
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+
mysql庫(kù)中存儲(chǔ)了MySQL的權(quán)限和用戶信息,也包含了一些系統(tǒng)變量和函數(shù)。我們可以通過(guò)該庫(kù)進(jìn)行用戶管理。
2. information_schema庫(kù)
mysql> use information_schema; Database changed mysql> show tables; +---------------------------------------+ | Tables_in_information_schema | +---------------------------------------+ | CHARACTER_SETS | | COLLATIONS | | COLLATION_CHARACTER_SET_APPLICABILITY | | COLUMNS | | COLUMN_PRIVILEGES | | ENGINES | | EVENTS | | FILES | | GLOBAL_STATUS | | GLOBAL_VARIABLES | | KEY_COLUMN_USAGE | | OPTIMIZER_TRACE | | PARAMETERS | | PARTITIONS | | PLUGINS | | PROCESSLIST | | PROFILING | | REFERENTIAL_CONSTRAINTS ……
information_schema庫(kù)中包含了關(guān)于MySQL表和數(shù)據(jù)庫(kù)元數(shù)據(jù)的信息。我們可以通過(guò)該庫(kù)獲得數(shù)據(jù)庫(kù)、表、列的相關(guān)信息。
3. performance_schema庫(kù)
mysql> use performance_schema; Database changed mysql> show tables; +-------------------------------------------------------+ | Tables_in_performance_schema | +-------------------------------------------------------+ | accounts | | binary_log_transaction_compression_stats | | cond_instances | | data_locks | | events_stages_current | | events_stages_history | | events_stages_history_long | | events_statements_current | | events_statements_history | | events_statements_history_long | | events_transactions_current | | events_transactions_history | | events_transactions_history_long | | exported_foreign_keys | | file_instances | | file_summary_by_event_name ……
performance_schema庫(kù)用于收集MySQL性能相關(guān)信息,包括線程、鎖、SQL語(yǔ)句執(zhí)行次數(shù)等。我們可以通過(guò)該庫(kù)進(jìn)行性能調(diào)優(yōu)。
4. sys庫(kù)
mysql> use sys; Database changed mysql> show tables; +----------------------+ | Tables_in_sys | +----------------------+ | all_grants | | all_roles | | all_role_edges | | all_routine_privs | | all_sequences | | all_tables | | all_views | | any_user_privileges | | applicable_roles | | attributes | | character_sets | | check_constraints | | collations | | column_privileges | | column_statistics | | columns | | column_types | | ……
sys庫(kù)是MySQL 5.7版本以后出現(xiàn)的一個(gè)庫(kù),用于提供一些方便的視圖和存儲(chǔ)過(guò)程來(lái)查詢數(shù)據(jù)。我們可以通過(guò)該庫(kù)進(jìn)行數(shù)據(jù)查看和分析。
總結(jié)
MySQL默認(rèn)庫(kù)的種類和作用分別是mysql庫(kù)(用戶權(quán)限和系統(tǒng)變量管理)、information_schema庫(kù)(數(shù)據(jù)庫(kù)和表元數(shù)據(jù)查詢)、performance_schema庫(kù)(性能數(shù)據(jù)收集和分析)和sys庫(kù)(數(shù)據(jù)查看和分析)。根據(jù)我們的實(shí)際需求,選擇合適的庫(kù)進(jìn)行操作和查詢。