首页 > 数据库 > MySQL > mysql 体系结构(二)
mysql 体系结构
--Initaillization module
when the server is started on the command line,the Initialization Module tasks control It parses the
configurarion file and the command-line arguments,allocates global memory buffers,intializes global variables
and strunctures,loads the access control tables,and performs a number of other initialization tasks.
Once the initialization job is complete,the Initialization module passwd control to the connection manager
,which starts listening for connections from clients in a loop.
--connect manger
--thread manager
--user authentication module
when a client connects to the database server,the connection manager performs a number of low-level network protocol
tasks and then passwd control the thread manager,which in trun supplies a thread to handle the connection(which from now
on will be referres to as the connection thread).The connection thread mugh be created new,or retrieved from the thread cache and
called to active duty.Once the connection thread receives control,it first invokes the user
authentication module.the creddentials of the connecting user are verified ,and the client may now issue requests.
mysql> show global variables like '%connect%';
+-----------------------------------------------+-----------------+
| Variable_name | Value |
+-----------------------------------------------+-----------------+
| character_set_connection | utf8 |
| collation_connection | utf8_general_ci |
| connect_timeout | 10 |
| disconnect_on_expired_password | ON |
| init_connect | |
| max_connect_errors | 100 |
| max_connections | 100 | 最大连接数
| max_user_connections | 0 | 对于MAX_USER_CONNECTIONS,限制为整数,表示账户一次可以同时连接的最大连接数。如果限制设置为 默认值零,则根据MAX_USER_CONNECTIONS系统变量确定该账户可以同时连接的数量。
| performance_schema_session_connect_attrs_size | 512 |
+-----------------------------------------------+-----------------+
mysql> show processlist;
+----+------+-----------------+------+---------+------+-------+-----------------
-+
| Id | User | Host | db | Command | Time | State | Info
|
+----+------+-----------------+------+---------+------+-------+-----------------
-+
| 3 | root | localhost:59694 | NULL | Sleep | 6784 | | NULL
|
| 4 | root | localhost:59695 | dsg | Sleep | 310 | | NULL
|
| 5 | root | localhost:59696 | dsg | Sleep | 310 | | NULL
|
| 6 | root | localhost:59697 | NULL | Sleep | 1 | | NULL
|
| 10 | root | localhost:59709 | NULL | Query | 0 | init | show processlist
|
+----+------+-----------------+------+---------+------+-------+-----------------
mysql 连接状态
mysql> show global status like '%conn%';
+-----------------------------------------------+-------+
| Variable_name | Value |
+-----------------------------------------------+-------+
| Aborted_connects | 3 |
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 0 |
| Connection_errors_peer_address | 0 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 16 |
| Max_used_connections | 7 |
| Performance_schema_session_connect_attrs_lost | 0 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 7 |
+-----------------------------------------------+-------+
14 rows in set (0.00 sec)
--command dispather
--logging module
--query cache module
the command dispather forwards queries to the parser through the query cache module.The query
cache module checks whether the query is of the type that can be cached.and if there exists a previously computed cached result that is still valid.
In the case of a hit,the execution is short-circuited at this point,the cached result is returned to the user,and the
connection thread receives control and is now ready to process another command.If the query cache module report a miss,the query
goes to the parser,which will make a decision on how to transfer control based on the query type.
--optimize
--table modification module
--table maintenance module
--replication module
--report module
one can be identify the following modules that could contine from that poing: the opeimizer,the tale modification module,the table maintenance module,the replcation module,and the status reporting module.
select queries are forwarded to the optimizer;updates,inserts,deletes;and table-creation and schmea-altering queries go to the
respective table modification modules;queries that check,repair,update key statistics,or defragment the table go to the
table mainenance module;queries related to replication go to the replication module; and status reques go to the stats report module.there also exist a number of table modification modules;
delte module,create module,update module,insert module and alter module
--acces control module
--table manager
--abstracted storage engine
at this point,each of the modules that will receive control from the parser passes the list of tables involved in thr query to he access control module and then,upon success,
to the table manager,which opens the tables and acquires the nessary locks. now the table operation module is readby to proceed with its specific task and will issue a number of request
to the abstracted storage engine module for low-level operations such as inserting or updating a record,retrieving the records based on a key value,or performing an operation on
the table level,such as repairing it or updating the indx statistics
查看系统表 User db host
mysql> use mysql
Database changed
mysql> show tables
-> ;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.02 sec)
ysql> desc db
-> ;
-----------------------+---------------+------+-----+---------+-------+
Field | Type | Null | Key | Default | Extra |
-----------------------+---------------+------+-----+---------+-------+
Host | char(60) | NO | PRI | | |
Db | char(64) | NO | PRI | | |
User | char(16) | NO | PRI | | |
Select_priv | enum('N','Y') | NO | | N | |
Insert_priv | enum('N','Y') | NO | | N | |
Update_priv | enum('N','Y') | NO | | N | |
Delete_priv | enum('N','Y') | NO | | N | |
Create_priv | enum('N','Y') | NO | | N | |
Drop_priv | enum('N','Y') | NO | | N | |
Grant_priv | enum('N','Y') | NO | | N | |
References_priv | enum('N','Y') | NO | | N | |
Index_priv | enum('N','Y') | NO | | N | |
Alter_priv | enum('N','Y') | NO | | N | |
Create_tmp_table_priv | enum('N','Y') | NO | | N | |
Lock_tables_priv | enum('N','Y') | NO | | N | |
Create_view_priv | enum('N','Y') | NO | | N | |
Show_view_priv | enum('N','Y') | NO | | N | |
Create_routine_priv | enum('N','Y') | NO | | N | |
Alter_routine_priv | enum('N','Y') | NO | | N | |
Execute_priv | enum('N','Y') | NO | | N | |
Event_priv | enum('N','Y') | NO | | N | |
Trigger_priv | enum('N','Y') | NO | | N | |
-----------------------+---------------+------+-----+---------+-------+
2 rows in set (0.02 sec)
--网络交互
--网络监听
--协议处理
--核心api
--内存管理
--数字、字符函数
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24577884/viewspace-1061538/ ,如需转载,请注明出处,否则将追究法律责任。