MySQL/MariaDB数据库的复制过滤器
MySQL/MariaDB数据库的复制过滤器
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.复制过滤器概述
1>.复制器过滤器功能
让从节点仅复制指定的数据库,或指定数据库的指定表。
2>.两种实现方式
方案一:
主服务器仅向二进制日志中记录与特定数据库相关的事件
此项和binlog_format相关,详情请参考官网说明:https://mariadb.com/kb/en/library/mysqld-options/#-binlog-ignore-db
binlog_do_db = 数据库白名单列表,多个数据库需多行实现
binlog_ignore_db = 数据库黑名单列表
问题:
基于二进制还原将无法实现(因为记录的日志只有部分数据库信息,可能存在部分数据无法还原的现象);不建议使用 方案二:
从服务器SQL_THREAD在replay中继日志中的事件时,仅读取与特定数据库(特定表)相关的事件并应用于本地
问题:
由于将master节点的所有数据都copy至slave节点,但SQL_THREAD线程仅读取与特定数据库(特定表)相关的事件并应用于本地,也就是说部分数据传过来也不去使用,这会造成网络及磁盘IO浪费。
3>.从服务器上的复制过滤器相关变量
MariaDB [(none)]> SHOW VARIABLES LIKE '%replicate%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| replicate_annotate_row_events | OFF |
| replicate_do_db | |
| replicate_do_table | |
| replicate_events_marked_for_skip | replicate |
| replicate_ignore_db | |
| replicate_ignore_table | |
| replicate_wild_do_table | |
| replicate_wild_ignore_table | |
+----------------------------------+-----------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW VARIABLES LIKE '%replicate%';
replicate_do_db=
指定复制库的白名单
replicate_ignore_db=
指定复制库黑名单
replicate_do_table=
指定复制表的白名单
replicate_ignore_table=
指定复制表的黑名单
replicate_wild_do_table= foo%.bar%
解决跨库更新的问题支持通配符
replicate_wild_ignore_table=
同上
二.复制过滤器在slave节点定义白名单案例
1>.master服务器配置
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[mysqld]
server-id =
binlog_format = row
log_bin = /data/mysql/logbin/master-
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf #查看配置文件
[root@node102.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /data/mysql/logbin/
total
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
-rw-rw---- mysql mysql Nov : aria_log.
-rw-rw---- mysql mysql Nov : aria_log_control
-rw-rw---- mysql mysql Nov : ibdata1
-rw-rw---- mysql mysql Nov : ib_logfile0
-rw-rw---- mysql mysql Nov : ib_logfile1
drwx------ mysql mysql Nov : mysql
srwxrwxrwx mysql mysql Nov : mysql.sock
drwx------ mysql mysql Nov : performance_schema
drwx------ mysql mysql Nov : test
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /data/mysql/logbin/
total
-rw-rw---- mysql mysql Nov : master-102.000001
-rw-rw---- mysql mysql Nov : master-102.000002
-rw-rw---- mysql mysql Nov : master-102.000003
-rw-rw---- mysql mysql Nov : master-.index
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl start mariadb #启动数据库实例
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+----------------------------+----------+
| user | host | password |
+------+----------------------------+----------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
+------+----------------------------+----------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'copy'@'172.30.1.10%' IDENTIFIED BY 'yinzhengjie';
Query OK, rows affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+----------------------------+-------------------------------------------+
| user | host | password |
+------+----------------------------+-------------------------------------------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
| copy | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
+------+----------------------------+-------------------------------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
在master节点上创建有复制权限的用户账号
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW MASTER LOGS;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-102.000001 | |
| master-102.000002 | |
| master-102.000003 | |
+-------------------+-----------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-102.000003 | | | |
+-------------------+----------+--------------+------------------+
row in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
MariaDB [(none)]> SHOW MASTER STATUS; #查看master当前二进制日志状态信息
2>.slave节点配置主从复制
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf #查看配置文件
[mysqld]
server-id =
binlog_format = row
read-only = on
replicate_do_db = devops
relay_log = relay-log-
relay_log_index = relay-log-.index
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf #编辑配置文件,指定值复制devops这个数据库
[root@node103.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
-rw-rw---- mysql mysql Nov : aria_log.
-rw-rw---- mysql mysql Nov : aria_log_control
-rw-rw---- mysql mysql Nov : ibdata1
-rw-rw---- mysql mysql Nov : ib_logfile0
-rw-rw---- mysql mysql Nov : ib_logfile1
drwx------ mysql mysql Nov : mysql
srwxrwxrwx mysql mysql Nov : mysql.sock
drwx------ mysql mysql Nov : performance_schema
drwx------ mysql mysql Nov : test
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node103.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CHANGE MASTER TO
-> MASTER_HOST='172.30.1.102',
-> MASTER_USER='copy',
-> MASTER_PASSWORD='yinzhengjie',
-> MASTER_PORT=,
-> MASTER_LOG_FILE='master-102.000003',
-> MASTER_LOG_POS=,
-> MASTER_CONNECT_RETRY=;
Query OK, rows affected (0.01 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 172.30.1.102
Master_User: copy
Master_Port:
Connect_Retry:
Master_Log_File: master-102.000003
Read_Master_Log_Pos:
Relay_Log_File: relay-log-103.000001
Relay_Log_Pos:
Relay_Master_Log_File: master-102.000003
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: devops
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> START SLAVE;
Query OK, rows affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.30.1.102
Master_User: copy
Master_Port:
Connect_Retry:
Master_Log_File: master-102.000003
Read_Master_Log_Pos:
Relay_Log_File: relay-log-103.000002
Relay_Log_Pos:
Relay_Master_Log_File: master-102.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: devops
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec) MariaDB [(none)]>
slave配置主从复制详细过程
3>.验证数据库配置是否生效
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> CREATE DATABASE db1;
Query OK, row affected (0.00 sec) MariaDB [(none)]> CREATE DATABASE db2;
Query OK, row affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> CREATE DATABASE db3;
Query OK, row affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> CREATE DATABASE devops;
Query OK, row affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| db3 |
| devops |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> USE devops
Database changed
MariaDB [devops]>
MariaDB [devops]> CREATE TABLE students(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,name VARCHAR() NOT NULL,sex ENUM('bo
y','girl') DEFAULT 'boy',age TINYINT UNSIGNED,mobile CHAR(11),address VARCHAR(50));Query OK, 0 rows affected (0.01 sec) MariaDB [devops]>
MariaDB [devops]> INSERT INTO students (name,age,mobile,address) VALUES ('Jason Yin',,,'beijing'),('Jay','',
,'Taiwan');Query OK, rows affected (0.01 sec)
Records: Duplicates: Warnings: MariaDB [devops]>
MariaDB [devops]> SHOW TABLES;
+------------------+
| Tables_in_devops |
+------------------+
| students |
+------------------+
row in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]> SELECT * FROM students;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]>
master节点创建多个测试数据库
[root@node103.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| devops |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> USE devops
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [devops]> SHOW TABLES;
+------------------+
| Tables_in_devops |
+------------------+
| students |
+------------------+
row in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]> SELECT * FROM students;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.01 sec) MariaDB [devops]>
MariaDB [devops]>
MariaDB [(none)]> QUIT
Bye
[root@node103.yinzhengjie.org.cn ~]#
slave节点发现只有一个数据库的信息过来啦
三.复制过滤器在master节点定义白名单案例
1>.master服务器配置
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[mysqld]
server-id =
binlog_format = row
log_bin = /data/mysql/logbin/master-
binlog_do_db = db2 #此处我们只记录db2的日志
binlog_do_db = devops #和上面一行累加起来,就是只记录db2和devops数据库的内容
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[root@node102.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /data/mysql/logbin/
total
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
-rw-rw---- mysql mysql Nov : aria_log.
-rw-rw---- mysql mysql Nov : aria_log_control
-rw-rw---- mysql mysql Nov : ibdata1
-rw-rw---- mysql mysql Nov : ib_logfile0
-rw-rw---- mysql mysql Nov : ib_logfile1
drwx------ mysql mysql Nov : mysql
srwxrwxrwx mysql mysql Nov : mysql.sock
drwx------ mysql mysql Nov : performance_schema
drwx------ mysql mysql Nov : test
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ll /data/mysql/logbin/
total
-rw-rw---- mysql mysql Nov : master-102.000001
-rw-rw---- mysql mysql Nov : master-102.000002
-rw-rw---- mysql mysql Nov : master-102.000003
-rw-rw---- mysql mysql Nov : master-.index
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+----------------------------+----------+
| user | host | password |
+------+----------------------------+----------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
+------+----------------------------+----------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'copy'@'172.30.1.10%' IDENTIFIED BY 'yinzhengjie';
Query OK, rows affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+------+----------------------------+-------------------------------------------+
| user | host | password |
+------+----------------------------+-------------------------------------------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
| copy | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
+------+----------------------------+-------------------------------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
在master节点上创建有复制权限的用户账号
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW MASTER LOGS;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-102.000001 | |
| master-102.000002 | |
| master-102.000003 | |
+-------------------+-----------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-102.000003 | | | |
+-------------------+----------+--------------+------------------+
row in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
MariaDB [(none)]> SHOW MASTER STATUS; #查看master当前二进制日志状态信息
2>.slave节点配置主从复制
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf #最好将之前配置的从节点白名单删除,以免影响试验结果
[mysqld]
server-id =
binlog_format = row
read-only = on
relay_log = relay-log-
relay_log_index = relay-log-.index
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf #最好将之前配置的从节点白名单删除
[root@node103.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# ll /var/lib/mysql/
total
-rw-rw---- mysql mysql Nov : aria_log.
-rw-rw---- mysql mysql Nov : aria_log_control
-rw-rw---- mysql mysql Nov : ibdata1
-rw-rw---- mysql mysql Nov : ib_logfile0
-rw-rw---- mysql mysql Nov : ib_logfile1
drwx------ mysql mysql Nov : mysql
srwxrwxrwx mysql mysql Nov : mysql.sock
drwx------ mysql mysql Nov : performance_schema
drwx------ mysql mysql Nov : test
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl start mariadb
[root@node103.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CHANGE MASTER TO
-> MASTER_HOST='172.30.1.102',
-> MASTER_USER='copy',
-> MASTER_PASSWORD='yinzhengjie',
-> MASTER_PORT=,
-> MASTER_LOG_FILE='master-102.000003',
-> MASTER_LOG_POS=,
-> MASTER_CONNECT_RETRY=;
Query OK, rows affected (0.01 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 172.30.1.102
Master_User: copy
Master_Port:
Connect_Retry:
Master_Log_File: master-102.000003
Read_Master_Log_Pos:
Relay_Log_File: relay-log-103.000001
Relay_Log_Pos:
Relay_Master_Log_File: master-102.000003
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: devops
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> START SLAVE;
Query OK, rows affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.30.1.102
Master_User: copy
Master_Port:
Connect_Retry:
Master_Log_File: master-102.000003
Read_Master_Log_Pos:
Relay_Log_File: relay-log-103.000002
Relay_Log_Pos:
Relay_Master_Log_File: master-102.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: devops
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec) MariaDB [(none)]>
slave配置主从复制详细过程
3>.验证数据库配置是否生效
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> CREATE DATABASE db1;
Query OK, row affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> CREATE DATABASE db2;
Query OK, row affected (0.00 sec) MariaDB [(none)]> CREATE DATABASE db3;
Query OK, row affected (0.00 sec) MariaDB [(none)]> CREATE DATABASE devops;
Query OK, row affected (0.00 sec) MariaDB [(none)]> USE devops
Database changed
MariaDB [devops]>
MariaDB [devops]> CREATE TABLE students(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,name VARCHAR() NOT NULL,sex ENUM('boy','girl') DEFAULT 'boy',age TINYINT UNSIGNED,mobile CHAR(),address VARCHAR());
Query OK, rows affected (0.01 sec) MariaDB [devops]>
MariaDB [devops]> INSERT INTO students (name,age,mobile,address) VALUES ('Jason Yin',,,'beijing'),('Jay','',,'Taiwan');
Query OK, rows affected (0.01 sec)
Records: Duplicates: Warnings: MariaDB [devops]>
MariaDB [devops]> SELECT * FROM students;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]> USE db2
Database changed
MariaDB [db2]>
MariaDB [db2]> CREATE TABLE test SELECT * FROM devops.students;
Query OK, rows affected (0.00 sec)
Records: Duplicates: Warnings: MariaDB [db2]>
MariaDB [db2]> SELECT * FROM test;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.00 sec) MariaDB [db2]>
MariaDB [db2]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| db3 |
| devops |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [db2]>
MariaDB [db2]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
master节点创建多个测试数据库
[root@node103.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db2 |
| devops |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> USE devops
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [devops]>
MariaDB [devops]> SHOW TABLES;
+------------------+
| Tables_in_devops |
+------------------+
| students |
+------------------+
row in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]> SELECT * FROM students;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.00 sec) MariaDB [devops]>
MariaDB [devops]> USE db2
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [db2]>
MariaDB [db2]> SHOW TABLES;
+---------------+
| Tables_in_db2 |
+---------------+
| test |
+---------------+
row in set (0.00 sec) MariaDB [db2]>
MariaDB [db2]> SELECT * FROM test;
+----+-----------+------+------+--------+---------+
| id | name | sex | age | mobile | address |
+----+-----------+------+------+--------+---------+
| | Jason Yin | boy | | | beijing |
| | Jay | boy | | | Taiwan |
+----+-----------+------+------+--------+---------+
rows in set (0.00 sec) MariaDB [db2]>
MariaDB [db2]> QUIT
Bye
[root@node103.yinzhengjie.org.cn ~]#
slave节点发现只有db2和devops两个数据库的信息过来啦
MySQL/MariaDB数据库的复制过滤器的更多相关文章
- MySQL/MariaDB数据库的复制监控和维护
MySQL/MariaDB数据库的复制监控和维护 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.清理日志 1>.删除指定日志文件名称之前的日志(也可用基于时间) M ...
- MySQL/MariaDB数据库的复制加密
MySQL/MariaDB数据库的复制加密 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的安全问题 1>.基于SSL复制 在默认的主从复制过程或远程连接 ...
- MySQL/MariaDB数据库的半同步复制
MySQL/MariaDB数据库的半同步复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL半同步复制概述 1>.MySQL默认的异步复制 默认情况下,M ...
- MySQL/MariaDB数据库的主主复制
MySQL/MariaDB数据库的主主复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主主复制概述 1>.什么是主主复制 所谓的主主复制,说白了就是两台节点互为 ...
- MySQL/MariaDB数据库的主从级联复制
MySQL/MariaDB数据库的主从级联复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主从复制类型概述 1>.主从复制 博主推荐阅读: https://ww ...
- MySQL/MariaDB数据库的Galera高可用性集群实战
MySQL/MariaDB数据库的Galera高可用性集群实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Galera Cluster概述 1>.什么是Gale ...
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- MySQL/MariaDB数据库的PROXY实现读写分离
MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...
- MySQL/MariaDB数据库的主从复制
MySQL/MariaDB数据库的主从复制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL复制概述 1>.传统扩展方式 垂直扩展(也叫向上扩展,Sacle ...
随机推荐
- MNN配置
1.github链接:https://github.com/alibaba/MNN/tree/master/tools/converter 2.教程 (1)使用教程:https://www.books ...
- 一款新的好用的SSH工具——FinalShell
FinalShell是一体化的的服务器,网络管理软件,不仅是ssh客户端,还是功能强大的开发,运维工具,充分满足开发,运维需求.特色功能:免费海外服务器远程桌面加速,ssh加速,双边tcp加速,内网穿 ...
- oracle 通用事务使用
private void dothing() { OracleConnection con = DBHelperOracle.init(); OracleTransaction tran = con. ...
- Math 类
Math 类 java.lang.Object java.lang.Math 方法签名 public final class Math extends Object public static fin ...
- [Windows] - 在 Windows Server 2019 找不到无线网卡 之解决
硬件:Intel® Dual Band Wireless-AC 3165系统:Windows Server 2019 问题:新系统安装完成后,无法找到无线网卡 尝试:适用于 Windows Serve ...
- MATLAB 安装 cvx 工具箱
步骤: matlab本身是没有cvx的工具箱,需要到[cvx主页],「http://cvxr.com/cvx/」上下载,菜单上有个「download」,进入后选择适合你的版本下载: 将cvx压缩包解压 ...
- js中常见的字符串方法(3)
match() match()方法只接受一个参数,要么是一个正则表达式,要么是一个 RegExp 对象. 调用这个方法本质上与调用RegExp的exec()方法相同, var text = " ...
- java之抽象类介绍
什么抽象方法和抽象类 抽象方法 在类里面定义的没有方法体且用关键字“abstract”来修饰的方法就是抽象方法,所谓的没有方法体指的是在方法声明的时候没有大括号以及其中的内容,而是直接在声明时在方法名 ...
- IQueryable,IEnumerable,IList区别
IQueryable和IEnumerable都是延时执行(Deferred Execution)的,而IList是即时执行(Eager Execution)IQueryable和IEnumerable ...
- Net实现钩子函数(Hook)以及通过SendMessage实现自动点击按钮和给文本框赋值
1.实现钩子函数 钩子(Hook)的实现需要三个主要的函数和一个委托 [DllImport("user32.dll", CharSet = CharSet.Auto, Callin ...