当前位置:网站首页>Introduction to MySQL system tables
Introduction to MySQL system tables
2022-06-23 07:49:00 【hzp666】
In the previous issue 《 Copy the information record form | Get to know mysql System libraries 》 in , We introduced in detail mysql Copy information record table in system library , In this issue, we will bring you the eighth in the series 《 Miscellaneous tables such as log records | Get to know mysql System libraries 》, Now please follow us to start mysql System library system learning tour !
Log information record table
01
1.1. Overview of log information
MySQL The log system contains :general query log、slow query log、error log( Record MySQL Server Startup time 、 Running 、 Stop error message )、binary log( Record MySQL Server Logical log of data changes during operation )、relay log( Record from library IO The main database data change log obtained by the thread from the main database )、DDL log( Record DDL Metadata change information during statement execution .5.7 Only writing to files is supported in ,8.0 Support writing to innodb_ddl_log In the table , Be careful ,ddl log And online ddl Of alter log Different , Don't confuse ), among , stay MySQL 5.7 in , Only general query log、slow query log Support writing to tables ( It also supports writing to files ), Other log types are in MySQL 5.7 Version only supports writing to files , therefore , The following is mainly about the log system table general query log、slow query log surface .
By default , except Windows In addition to the error log on , All logs of other platforms are not enabled by default (DDL Logs are created only when needed , And there are no user configurable options ).
By default , All the logs are written in datadir Under the table of contents , But you can use the path parameters corresponding to each log to change the path .
general query log:general_log_file=/home/mysql/data/mysqldata1/mydata/localhost.log
error log:log_error=/home/mysql/data/mysqldata1/log/error.log
slow query log:slow_query_log_file=/home/mysql/data/mysqldata1/slowlog/slow-query.log
binary log:log_bin_basename=/home/mysql/data/mysqldata1/binlog/mysql-bin、log_bin_index=/home/mysql/data/mysqldata1/binlog/mysql-bin.index
relay log:relay_log_basename=/home/mysql/data/mysqldata1/relaylog/mysql-relay-bin、relay_log_index=/home/mysql/data/mysqldata1/relaylog/mysql-relay-bin.index
By default , All logs are written to disk files , but general query log and slow query log Can pass log_output=TABLE Save settings to table mysql.general_log and mysql.slow_log In the table (DDL log stay 8.0 Medium configurable , It can be printed to the error log , It can also be saved in the table innodb_ddl_log in ).
By default ,binary log according to max_binlog_size The size of parameter setting is automatically scrolled 、relay log according to max_relay_log_size perhaps max_binlog_size Auto scroll ( If max_relay_log_size If it's not set, just follow max_binlog_size Size scrolling ), Other log types don't scroll , Always use the same file , So after other log types grow too much , You need to cut yourself .
In general use mv file file.bak; Then execute the refresh command , The refresh command can be used by login instance flush logs Command refresh to regenerate a new log file , But the command is to refresh all log types , For specific log types , have access to :flush binary logs; Refresh binary log 、flush error logs; Refresh the error log 、flush general logs; Refresh the normal query log 、flush slow logs; Refresh slow query log 、flush relay logs; Refresh relay log 、flush engine logs; Refresh any refreshable logs related to the storage engine .
You can also use Server Of flush tables; Statements or flush table with read lock; sentence .
The refresh operation can also be implemented with the options of some command-line tools , for example : Use mysqladmin Ordered flush-logs Options , perhaps mysqldump Of flush-logs Options and --master-data Options .
The log table implementation has the following features :
Usually , The main purpose of log table is to provide an access interface for the program , In order to see Server Internal SQL Operation of the , therefore , It is more convenient to store log records in tables than in disk files , Because it's stored in a table, you can access these log records remotely , You don't need to log in to the operating system to access disk files .
Log table can be used CREATE TABLE,ALTER TABLE and DROP TABLE sentence , But the premise is to use the corresponding switch to turn off the meter , Cannot operate during use ( for example :set global general_log=0, Then operate general_log surface ).
general_log and slow_log The default table is CSV engine , Use comma separated format to store log records ,CSV Data files can be easily imported into other programs for processing , for example :excel The spreadsheet .
The log table can be modified to MyISAM, But you must stop using the table before you modify it . The legal engine is CSV and MyISAM, Other engines don't support .
To disable the logging table for the corresponding DDL Statement operation , You can use the following steps ( Take the slow query table as an example ,slow_log and general_log Table operations are similar to ).
SET @old_log_state = @@ global.general_log;SET GLOBAL general_log ='OFF';ALTER TABLE mysql.general_log ENGINE = MyISAM;SET GLOBAL general_log = @old_log_state;
have access to TRUNCATE TABLE To clear the log .
have access to RENAME TABLE To archive the log table , The old and new tables do an operation of exchanging the names of atoms , as follows :
use mysql;DROP TABLE IF EXISTS general_log2;CREATE TABLE general_log2 LIKE general_log;RENAME TABLE general_log TO general_log_backup,general_log2 TO general_log;
matters needing attention
have access to CHECK TABLE sentence .
Out of commission LOCK TABLE sentence .
Out of commission INSERT,DELETE and UPDATE sentence , Changes to the log table are made by Server Internal maintenance , It can't be operated manually .
FLUSH TABLES WITH READ LOCK and read_only The setting of system variables has no effect on the log table .Server Log tables can always be written internally .
The data change operation of log table will not record binlog, So it won't be copied to the slave Library .
have access to FLUSH TABLES or FLUSH LOGS Statement to refresh the log table or log file .
Log table does not support partition table .
mysqldump The dump contains statements to recreate these tables , To restore the log table structure after reloading the dump file , But the records in the log table will not be dumped .
PS:MySQL Query log 、 Error logs, etc. are recorded in clear text , therefore , These logs may record the user's clear text password information , have access to rewrite Plug in to record in the original format , For details, see links. :
https://dev.mysql.com/doc/refman/5.7/en/plugin-types.html#query-rewrite-plugin-type
https://dev.mysql.com/doc/refman/5.7/en/rewriter-query-rewrite-plugin.html
1.2. Log sheet details
1.2.1. general_log
This table provides query common SQL Statement execution record information , It is used to find out what the client is executing on the server SQL( Of course , You can also use the enterprise version of audit log Audit plug-in records , This article does not elaborate , Interested children's shoes to study by themselves ).
The information in this table is in SQL It's recorded at the beginning of execution , Instead of waiting SQL Record only at the end of execution .
The following is the information stored in the table .
[email protected] : (none) 07:25:50> set global log_output='TABLE';Query OK, 0 rows affected (0.00 sec)[email protected] : (none) 07:26:20> set global general_log=1;Query OK, 0 rows affected (0.01 sec)[email protected] : (none) 07:26:32> select * from mysql.general_log;+----------------------------+---------------------------+-----------+-----------+--------------+---------------------------------+| event_time | user_host | thread_id | server_id | command_type | argument |+----------------------------+---------------------------+-----------+-----------+--------------+---------------------------------+| 2018-06-19 19:26:32.891371 | root[root] @ localhost [] | 3 | 3306102 | Query | show databases || 2018-06-19 19:26:42.012064 | root[root] @ localhost [] | 3 | 3306102 | Query | select * from mysql.general_log |+----------------------------+---------------------------+-----------+-----------+--------------+---------------------------------+2 rows in set (0.00 sec)[email protected] : (none) 07:26:42> select connection_id();+-----------------+| connection_id() |+-----------------+| 3 |+-----------------+1 row in set (0.00 sec)
Table field meaning .
event_time: The moment the query log records to the table log_timestamps System variable value , Used to mark when query log records are put into storage .
user_host: Represents the source of the query log record , There are user name and host name information .
thread_id: Indicates when the query log record is executed process_id.
server_id: Represents the database instance that executed the query ID.
command_type: Represents the query command type , It's usually for query.
argument: Represents the execution of the query SQL The statement text .
mysqld Write the statements to the query log in the order of receiving requests ( This may be different from the order in which they are executed ).
In the master-slave replication Architecture .
When using statement based log format on the main library , After replaying these statements from the library , These statements will be recorded in their own query log ( Query logging needs to be enabled from the library ), Recorded in statement format binlog In the use of mysqlbinlog When the command is parsed and imported into the database , If the instance has enabled the query logging function , These parsing statements will also be recorded in the query log .
The main database is based on row Log format , After replaying these data changes from the library , These statements are not included in the query log from the library .
Use on the master library based on mixed Log format , If the main library is recorded in statement format , After replaying the data from the library, the statement will be recorded in its own query log ( Query logging needs to be enabled from the library ), If the master database is recording binlog Is converted to row Format , It also follows row The format is copied the same , Replaying these data changes from the library will not record these statements to your query log .
Query logs can use system variables sql_log_off Variable dynamically turns off the query logging function of the current session or all sessions ( And sql_log_bin The function of system variables is similar to ).
Query log switch general_log Variable and query disk log file path general_log_file Variables can be modified dynamically ( If a query log is already open , Then use general_log_file Variable to modify the query log path to close the old query log , Open a new query log ), When query logging is enabled , The query log will be maintained to the system variable log_output Designated destination .
If query logging is enabled , be Server The query log file will be reopened on restart , If there is a log query , Open it again , If the query log does not exist , Then recreate , If you need to Server Archive dynamic query runtime , You can follow the following command (linux perhaps unix platform ).
shell> mv host_name.log host_name-old.logshell> mysqladmin flush-logsshell> mv host_name-old.log backup-directory# stay Windows On , Please use rename directly , instead of mv command
It can also be in Server At run time, the query log function is first turned off by statements , Then use external commands to archive , Then re enable the query log , So you don't need to use flush-logs Command to refresh the log file , This method can be applied to any platform , The order is as follows :
SET GLOBAL general_log ='OFF';# With logging Disabled , Rename the log file from the outside ; for example , From the command line . Then enable logging again :SET GLOBAL general_log ='ON';# This method can be applied to any platform , There is no need to restart the server .
By default , stay Server If the statement executed in is with the user password , Will be Server Rewrite the statement and write it to the query log , If you need to record clear text passwords , You need to use --low-raw Option to start the Server( Using this option will bypass the password rewriting function ), It is generally not recommended to record the password plaintext information in the query log , Because it's not safe , But if necessary , Judge for yourself ( for example : When you need to query the original statement information to troubleshoot the problem ).
If the password in the statement , Specifies that the password is a hash When the value of , The password string will not be rewritten , for example :CREATE USER 'user1'@'localhost' IDENTIFIED BY PASSWORD 'not-so-secret'; It will be recorded for the original reason , But if you remove PASSWORD keyword CREATE USER 'user1'@'localhost' IDENTIFIED BY 'not-so-secret';, In the query log, it will be rewritten as :CREATE USER 'user1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS ''.
Some grammatical mistakes SQL By default, it will not be recorded in the query log , Use --low-raw Option to start the Server Will record all the original SQL sentence .
The timestamp information in the query log table comes from the system variable log_timestamps( The timestamp in both the slow query log file and the error log file comes from the value of this system variable ), The timestamp value can be used when querying CONVERT_TZ() Function or by setting the session to convert the timestamp information from these tables from the local system time zone to any desired time zone ( Modify session level time_zone A variable's value ).
1.2.2. slow_log
The query execution time of this table exceeds long_query_time Set value's SQL, Or not using the index ( Need to turn on parameters log_queries_not_using_indexes=ON) Or management statements ( Need to turn on parameters log_slow_admin_statements=ON).
The following is the information stored in the table .
[email protected] : test 08:46:04> set global long_query_time=0;Query OK, 0 rows affected (0.01 sec)[email protected] : test 08:55:14> set global slow_query_log=1;Query OK, 0 rows affected (0.01 sec)# Disconnect the session and re connect[email protected] : (none) 08:56:12> use testDatabase changed[email protected] : test 08:56:13> show tables;+----------------+| Tables_in_test |+----------------+| customer || product || shares || test || transreq |+----------------+5 rows in set (0.01 sec)[email protected] : test 08:56:16> select * from test;+---+---+------+------+------+------+| a | b | c | d | e | f |+---+---+------+------+------+------+| 1 | 1 | 1 | 1 | 1 | 1 || 2 | 2 | 2 | 2 | 2 | 2 || 3 | 3 | 3 | 3 | 3 | 3 || 4 | 4 | 4 | 4 | 4 | 4 || 5 | 5 | 4 | 4 | 5 | 5 |+---+---+------+------+------+------+5 rows in set (0.01 sec)[email protected] : test 08:56:18> select * from mysql.slow_log;+----------------------------+---------------------------+-----------------+-----------------+-----------+---------------+------+----------------+-----------+-----------+----------------------------------+-----------+| start_time | user_host | query_time | lock_time | rows_sent | rows_examined | db | last_insert_id | insert_id | server_id | sql_text | thread_id |+----------------------------+---------------------------+-----------------+-----------------+-----------+---------------+------+----------------+-----------+-----------+----------------------------------+-----------+| 2018-06-19 20:56:12.254716 | root[root] @ localhost [] | 00:00:00.000286 | 00:00:00.000000 | 1 | 0 | | 0 | 0 | 3306102 | select @@version_comment limit 1 | 4 || 2018-06-19 20:56:12.258551 | root[root] @ localhost [] | 00:00:00.000153 | 00:00:00.000000 | 1 | 0 | | 0 | 0 | 3306102 | select USER() | 4 || 2018-06-19 20:56:13.975382 | root[root] @ localhost [] | 00:00:00.000247 | 00:00:00.000000 | 1 | 0 | | 0 | 0 | 3306102 | SELECT DATABASE() | 4 || 2018-06-19 20:56:13.975627 | root[root] @ localhost [] | 00:00:00.000095 | 00:00:00.000000 | 1 | 0 | test | 0 | 0 | 3306102 | Init DB | 4 || 2018-06-19 20:56:16.277207 | root[root] @ localhost [] | 00:00:00.000490 | 00:00:00.000264 | 5 | 5 | test | 0 | 0 | 3306102 | show tables | 4 || 2018-06-19 20:56:18.936831 | root[root] @ localhost [] | 00:00:00.000694 | 00:00:00.000400 | 5 | 5 | test | 0 | 0 | 3306102 | select * from test | 4 |+----------------------------+---------------------------+-----------------+-----------------+-----------+---------------+------+----------------+-----------+-----------+----------------------------------+-----------+6 rows in set (0.00 sec)
Table field meaning .
start_time: When the slow query log is recorded to the table log_timestamps System variable value .
user_host: With user name and host name (IP) Value of format , Used to mark access sources .
query_time: Total execution time of slow query statements .
lock_time: The time that a slow query statement holds a lock .
rows_sent: The number of data records finally returned to the client by the slow query statement .
rows_examined: The number of check records for slow query statements in the storage engine .
db: The default library name when the slow query statement is executed .
last_insert_id: Usually it is 0.
insert_id: Usually it is 0.
server_id: Generating slow query statements server id.
sql_text: Slow query log statement text .
thread_id: The thread that generates the slow query log process_id.
Slow query logs contain execution times longer than long_query_time The number of seconds set by the system variable SQL sentence , And it includes the need to check that the number of lines exceeds min_examined_row_limit The value set by the system variable SQL sentence ( By default, the variable is 0, It means that there is no limit to the number of check lines ).long_query_time The minimum and default values of are 0 and 10( Unit second ). The value can be specified as microseconds ( Use decimals ), But microsecond units are only valid for recording to a file . For slow query statements recorded in the table , Microseconds are not supported , The microsecond part is ignored .
By default , Slow query logs do not record management statements , It also does not record statements that do not use indexes , But you can use log_slow_admin_statements and log_queries_not_using_indexes System variables change the default behavior , send MySQL Server Add management statements and statements that do not use indexes into the slow query log .
In slow query log, the time when the statement obtains the initial lock is not included in the execution time , The inclusive time range is : After getting the lock , And after the statement is executed , Before releasing the lock . Then write the slow query statement into the slow query log . therefore , The order recorded in the slow query log may be the same as MySQL Server The order of statements received ( Execution order ) Is not the same , Because there may be statements that execute first and then release all locks , Some post execution statements release all locks first .
By default , Slow query log is not enabled . To enable, you can use --slow_query_log =1 Set it up , To specify the slow query log file name , have access to --slow_query_log_file = file_name Set it up , To specify the slow query log output target , have access to --log-output=FILE|TABLE|NONE Set it up .
If slow query logging is enabled , But no name was specified , The default is datadir The next name is host_name-slow.log, If you use --log-output=TABLE Set error report in the table , be slow_query_log_file = file_name Invalid path set .
To dynamically modify the slow query log file name , have access to slow_query_log=0 Close the slow query log file first , And then use slow_query_log_file=new_file_name Specify a new slow query log file name , And then use slow_query_log=1 Re enable slow query log files .
If mysqld In the start-up, it uses --log-short-format Options , be MySQL Server Slow queries will be written to the log .
If used log_slow_admin_statements=1 Set up , be MySQL Server The following management statements will be recorded in the slow query log :
ALTER TABLE,ANALYZE TABLE,CHECK TABLE,CREATE INDEX,DROP INDEX,OPTIMIZE TABLE and REPAIR TABLE
If used log_queries_not_using_indexes=1 Set up , be MySQL Server Any query statements that do not use an index are recorded in the slow query log .
When you record these queries , Slow query logs can grow rapidly . At this time, you can set log_throttle_queries_not_using_indexes The system variable is used to limit the rate at which these non indexed statements are counted into the slow query log ( Be careful : This variable limits 60 The number of unused index statements per second , It's not a time limit ). By default , This variable is 0, There is no rate limit . When restrictions are enabled , After the first query without an index is executed , Will open a 60 Second time window , In this window , Log queries that do not use other indexes to slow query logs , Wait for the time window to end ,Server Record a summary message , Indicates how many times and the total time spent on these execution times . And then go to the next 60 Second window .
MySQL Server Use the following order to determine whether statements need to be included in slow queries :
Judgment parameters log_slow_admin_statements Is it enabled? , If enabled , Then judge whether the statement is a management statement , If it is Slow queries are included , If it is not, it will enter the next round of judgment . If the parameter is not enabled , Then go to the next step to judge .
Judge whether the execution time of query statement exceeds long_query_time second , If it exceeds, it will be counted as slow query , If not more than , Then judge log_queries_not_using_indexes Whether the parameter is enabled , If this parameter is enabled and the statement does not use an index , Slow queries are included , Otherwise, go to the next step of judgment .
If min_examined_row_limit Variable set non-zero value , Then judge whether the number of check lines of the statement exceeds the value set by the variable , If it exceeds, it will be counted as slow query , If not, slow queries are not recorded .
The timestamp of the slow query log record is made by log_timestamps System variable control .
By default , The slave Library in the replication schema will not be replayed binlog The generated slow query is written into its own slow query log , If records need to be replayed from the library binlog The slow query statement is included in the slow query log , Variables need to be enabled log_slow_slave_statements=1.
The password in the statement written to the slow query log is rewritten by the server , It doesn't appear in plain text . If you need to record the original statement , Need to use --log-raw Options .
Hybrid table
02
Because this series does not introduce the enterprise version authentication plug-in audit_log_filter, audit_log_user surface 、 Firewall plug-in firewall_users, firewall_whitelis surface , So there's only one left servers There's not enough space in the hybrid table to start another issue , So we're forcing it into this issue , Mainly federated Information used by the engine , If you are not interested, you can skip the following contents of this issue .
2.1. servers
This table provides query join combination information ( Remote instance IP、 port 、 Account number 、 password 、 Database name and other information , See the following example ), This connection combination information is usually used for federated engine ( Of course, it can also be used as a way to save the connection combination in the database , Maintenance is also more convenient ), The information in this table needs to use create server Way to create .
Before introducing the meaning of other fields , Have a look first dederated Two ways to create engine .
# Use create server Method to create a combination of connectionsSyntax:CREATE SERVER server_nameFOREIGN DATA WRAPPER wrapper_nameOPTIONS (option [, option] ...)option:{ HOST character-literal| DATABASE character-literal| USER character-literal| PASSWORD character-literal| SOCKET character-literal| OWNER character-literal| PORT numeric-literal }# Use it directly CONNECTION Option to specify the complete connection combinationCONNECTION=scheme://user_name[:password]@host_name[:port_num]/db_name/tbl_name
The following is the information stored in the table .
[email protected] Tue Jun 5 01:12:05 2018 01:12:05 [(none)]>CREATE SERVER fedlink_ip-> FOREIGN DATA WRAPPER mysql-> OPTIONS (USER 'test',PASSWORD 'test', HOST '127.0.0.1', PORT 3306, DATABASE 'test_table',Owner 'test_table1');Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 01:12:10 2018 01:12:10 [(none)]>CREATE SERVER fedlink_socket-> FOREIGN DATA WRAPPER mysql-> OPTIONS (USER 'test',PASSWORD 'test', SOCKET '/data/mysql/mysql3306/data/mysql.sock', PORT 3306, DATABASE 'test_table',Owner 'test_table2');Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 01:12:10 2018 01:12:10 [(none)]>CREATE SERVER fedlink_socket_ip-> FOREIGN DATA WRAPPER mysql-> OPTIONS (USER 'test',PASSWORD 'test', HOST '127.0.0.1',SOCKET '/data/mysql/mysql3306/data/mysql.sock', PORT 3306, DATABASE 'test_table',Owner 'test_table3');Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 01:12:10 2018 01:12:10 [(none)]>select * from mysql.servers;+-------------------+-----------+------------+----------+----------+------+---------------------------------------+---------+-------------+| Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner |+-------------------+-----------+------------+----------+----------+------+---------------------------------------+---------+-------------+| fedlink_socket_ip | 127.0.0.1 | test_table | test | test | 3306 | /data/mysql/mysql3306/data/mysql.sock | mysql | test_table3 || fedlink_socket | | test_table | test | test | 3306 | /data/mysql/mysql3306/data/mysql.sock | mysql | test_table2 || fedlink_ip | 127.0.0.1 | test_table | test | test | 3306 | | mysql | test_table1 |+-------------------+-----------+------------+----------+----------+------+---------------------------------------+---------+-------------+3 rows in set (0.00 sec)# If you want to combine records , You can use the following statement[email protected] Tue Jun 5 01:10:41 2018 01:10:41 [(none)]>drop SERVER fedlink;Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 01:11:30 2018 01:11:30 [(none)]>drop SERVER fedlink_socket ;Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 01:11:55 2018 01:11:55 [(none)]>drop SERVER fedlink_socket_ip;Query OK, 1 row affected (0.00 sec)
federated Two ways to use the engine to read and write remote instance data examples .
# Create remote instance users[email protected] Tue Jun 5 00:23:45 2018 00:23:45 [(none)]>grant all on *.* to [email protected]'%' identified by 'test';Query OK, 0 rows affected (0.00 sec)# Create a library for storing remote instance tables[email protected] Tue Jun 5 00:24:06 2018 00:24:06 [(none)]>create database test_table;Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 00:30:50 2018 00:30:50 [(none)]>use test_tableDatabase changed# Create remote instance table test_table1 and test_table2[email protected] Tue Jun 5 00:31:03 2018 00:31:03 [test_table]>CREATE TABLE test_table1 (-> id INT(20) NOT NULL AUTO_INCREMENT,-> name VARCHAR(32) NOT NULL DEFAULT '',-> other INT(20) NOT NULL DEFAULT '0',-> PRIMARY KEY (id),-> INDEX name (name),-> INDEX other_key (other)-> );Query OK, 0 rows affected (0.06 sec)[email protected] Tue Jun 5 00:31:09 2018 00:31:09 [test_table]>CREATE TABLE test_table2 (-> id INT(20) NOT NULL AUTO_INCREMENT,-> name VARCHAR(32) NOT NULL DEFAULT '',-> other INT(20) NOT NULL DEFAULT '0',-> PRIMARY KEY (id),-> INDEX name (name),-> INDEX other_key (other)-> );Query OK, 0 rows affected (0.00 sec)# Create and store federated Library of engine tables[email protected] Tue Jun 5 00:31:16 2018 00:31:16 [test_table]>create database federated;Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 00:31:22 2018 00:31:22 [test_table]>use federatedDatabase changed# Use create server Method to create a connection string combination , The record will be saved to mysql.servers In the table[email protected] Tue Jun 5 00:31:25 2018 00:31:25 [federated]>CREATE SERVER fedlink-> FOREIGN DATA WRAPPER mysql-> OPTIONS (USER 'test',PASSWORD 'test', HOST '127.0.0.1', PORT 3306, DATABASE 'test_table');Query OK, 1 row affected (0.03 sec)# see mysql.servers The records in the table[email protected] Tue Jun 5 00:31:37 2018 00:31:37 [federated]>select * from mysql.servers;+-------------+-----------+------------+----------+----------+------+--------+---------+-------+| Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner |+-------------+-----------+------------+----------+----------+------+--------+---------+-------+| fedlink | 127.0.0.1 | test_table | test | test | 3306 | | mysql | |+-------------+-----------+------------+----------+----------+------+--------+---------+-------+1 row in set (0.00 sec)# Use create server Connection string combination mode , establish federated Engine watch[email protected] Tue Jun 5 00:32:12 2018 00:32:12 [federated]>CREATE TABLE federated1 (-> id INT(20) NOT NULL AUTO_INCREMENT,-> name VARCHAR(32) NOT NULL DEFAULT '',-> other INT(20) NOT NULL DEFAULT '0',-> PRIMARY KEY (id),-> INDEX name (name),-> INDEX other_key (other)-> )-> ENGINE=FEDERATED-> CONNECTION='fedlink/test_table1';Query OK, 0 rows affected (0.04 sec)[email protected] Tue Jun 5 00:32:17 2018 00:32:17 [federated]>show create table federated1;...| Table | Create Table |...| federated1 | CREATE TABLE `federated1` (`id` int(20) NOT NULL AUTO_INCREMENT,`name` varchar(32) NOT NULL DEFAULT '',`other` int(20) NOT NULL DEFAULT '0',PRIMARY KEY (`id`),KEY `name` (`name`),KEY `other_key` (`other`)) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='fedlink/test_table1' |...1 row in set (0.00 sec)# Go to federated Engine watch federated1 Insert data , Then you can go to federated The same data is found in both the engine table and the remote instance table[email protected] Tue Jun 5 00:32:58 2018 00:32:58 [federated]>insert into federated1(name) values('federated1');Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 00:33:42 2018 00:33:42 [federated]>select * from federated1;+----+------------+-------+| id | name | other |+----+------------+-------+| 1 | federated1 | 0 |+----+------------+-------+1 row in set (0.00 sec)[email protected] Tue Jun 5 00:33:49 2018 00:33:49 [federated]>select * from test_table.test_table1;+----+------------+-------+| id | name | other |+----+------------+-------+| 1 | federated1 | 0 |+----+------------+-------+1 row in set (0.00 sec)# Use CONNECTION Method complete connection string creation federated Engine watch[email protected] Tue Jun 5 00:32:32 2018 00:32:32 [federated]>CREATE TABLE federated2 (-> id INT(20) NOT NULL AUTO_INCREMENT,-> name VARCHAR(32) NOT NULL DEFAULT '',-> other INT(20) NOT NULL DEFAULT '0',-> PRIMARY KEY (id),-> INDEX name (name),-> INDEX other_key (other)-> )-> ENGINE=FEDERATED-> CONNECTION='mysql://test:[email protected]:3306/test_table/test_table2';Query OK, 0 rows affected (0.00 sec)# Go to federated Engine watch federated2 Insert data , Then you can go to federated The same data is found in both the engine table and the remote instance table[email protected] Tue Jun 5 00:34:08 2018 00:34:08 [federated]>insert into federated2(name) values('federated2');Query OK, 1 row affected (0.00 sec)[email protected] Tue Jun 5 00:34:16 2018 00:34:16 [federated]>select * from test_table.test_table2;+----+------------+-------+| id | name | other |+----+------------+-------+| 1 | federated2 | 0 |+----+------------+-------+1 row in set (0.00 sec)[email protected] Tue Jun 5 00:34:22 2018 00:34:22 [federated]>select * from federated2;+----+------------+-------+| id | name | other |+----+------------+-------+| 1 | federated2 | 0 |+----+------------+-------+1 row in set (0.00 sec)[email protected] Tue Jun 5 00:34:28 2018 00:34:28 [federated]>select * from mysql.servers;+-------------+-----------+------------+----------+----------+------+--------+---------+-------+| Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner |+-------------+-----------+------------+----------+----------+------+--------+---------+-------+| fedlink | 127.0.0.1 | test_table | test | test | 3306 | | mysql | |+-------------+-----------+------------+----------+----------+------+--------+---------+-------+1 row in set (0.00 sec)# Use socket Similar way , If you use socket when ,create server Connection combination creation method reference " Table record content example "
Table field meaning .
Server_name: Connection combination unique identifier ( That is the name , Use drop server When deleting a connection combination record , Directly specify the... Existing in the table server_name You can delete the combined records , Such as :drop server server_name;).
Host: Remote host name in connection composition (IP Or domain name ), Corresponding create server Medium HOST, Corresponding CONNECTION Concatenate... In a composite string host_name.
Db: The database name of the remote instance in the connection composition , Corresponding create server Medium DATABASE , Corresponding CONNECTION Concatenate... In a composite string db_name.
Username: Combination of remote user names for instance , Corresponding create server Medium USER , Corresponding CONNECTION Concatenate... In a composite string user_name.
Password: Remote instance user password for connection combination , Corresponding create server Medium PASSWORD , Corresponding CONNECTION Concatenate... In a composite string password.
Port: Connect the combined remote instance port , Corresponding create server Medium PORT , Corresponding CONNECTION Concatenate... In a composite string port_num.
Socket: Connect the local instance of the composition socket route , Corresponding create server Medium SOCKET , Corresponding CONNECTION Concatenate... In a composite string host_name.
Wrapper: It's like a protocol name , Corresponding create server Medium WRAPPER , Corresponding CONNECTION Concatenate... In a composite string scheme.
PS:
CONNECTION String mode will not be in mysql.servers Add records to the table .
So far as this issue is concerned , The links to this issue are as follows :
https://dev.mysql.com/doc/refman/5.7/en/federated-create-server.html
https://dev.mysql.com/doc/refman/5.7/en/server-logs.html
“
" Over this mountain , You can see a sea !". Keep reading our " Get to know mysql System libraries " Series article sharing , You can learn it systematically . Thanks for reading , We'll see you next time !
”
| Author's brief introduction
Luoxiaobo ·ScaleFlux Database technology experts
《 A golden prescription ——MySQL Performance optimization pyramid rule 》、《 Data Ecology :MySQL Replication technology and production practice 》 One of the authors .
be familiar with MySQL Architecture , Good at overall database tuning , I like studying open source technology , And keen on the promotion of open source technology , Online and offline have done many public database special sharing , Published recently 100 Database related research articles .
The full text after .
Enjoy MySQL :)
边栏推荐
- Vs problems when connecting to SQL myconn OPen(); cannot execute
- Analysis of open API design specification
- [* * * array * * *]
- Both are hard disk partitions. What is the difference between C disk and D disk?
- Mathematical knowledge: fast power fast power
- MIT CMS.300 Session 12 – IDENTITY CONSTRUCTION 虚拟世界中身份认同的建立 part 2
- [pit stepping record] a pit where the database connection is not closed and resources are released
- MySQL系统表介绍
- The road to hcip MPLS
- Product axure9 (English version), prototype design background dynamic secondary menu display content
猜你喜欢

HCIP之路第八次实验

30 sets of report templates necessary for the workplace, meeting 95% of the report needs, and no code is required for one click application

How to tag and label naming before the project release

Using the for loop to output an alphabetic triangle

Product axure9 (English version), prototype design background dynamic secondary menu display content

【PyQt5系列】修改计数器实现控制

HCIP之路MPLS

Eureka service registration and discovery

Gif verification code analysis

这道字符串反转的题目,你能想到更好的方法吗?
随机推荐
测试apk-异常管控NetTraffic攻击者开发
Product axure9 (English version), prototype design and production pull-down secondary menu
Make a record of glib2.14 upgrading glib2.18 and the principle of the steps
Query on the performance of multi table view in MySQL
RTMP streaming exception fast recovery scheme
Download the OSS file and modify the file name
[cloud computing event] vocational skill competition -- container development example pig rapid development framework
Can you think of a better way to solve the problem of string inversion?
快速排序 + 冒泡排序 + 插入排序 + 選擇排序
QT project error: -1: error: cannot run compiler 'clang++' Output:mingw32-make. exe
[markdown] markdown tutorial summary
Unity to wechat applet games
Playwirght深度入门
Design of temperature detection and alarm system based on 51 single chip microcomputer
Eureka service registration and discovery
How MySQL converts a date to a number
GIF验证码分析
这道字符串反转的题目,你能想到更好的方法吗?
数学知识:快速幂求逆元—快速幂
CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准