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 ...
随机推荐
- sql 在查询到的语句基础上添加行号
正常查询语句: SELECT TagName FROM ps_status a WHERE a.TagName LIKE "DTmk_zybf%1bxxjcqh.PV" 查询结果: ...
- Linux whereis、find和locate命令区别以及应用场景
查找某个文件是我们在使用使用linux中非常常用的一个命令. linux中有多个查找文件的指令:whereis.find.locate都有类似查找的功能,下面将讲解这些指令之间的区别. whereis ...
- [Docker] 六步运行一个 sentry 实例
# 6步, https://hub.docker.com/_/sentry/ # 依赖Redisdocker run -d --name sentry-redis redis:3.2.12 # 依赖p ...
- Java的三大版本
Java的三大版本 Write Once.Run Anywhere JavaSE:标准版(桌面程序,控制台开发......) JavaME:嵌入式开发(手机,小家电......) JavaEE:E企业 ...
- dell服务器在bios中指定raid5的热备盘
一.创建raid5 二.指定热备盘 选择第15块磁盘作为上面创建的raid5的热备盘 选中 选中我们刚创建的raid5,点击OK
- PAT 1098
1098 Insertion or Heap Sort (25 分) According to Wikipedia: Insertion sort iterates, consuming one ...
- SQL Server sp_monitor使用
SQL Server提供了sp_monitor存储过程可以方便我们查看SQL Server性能统计信息,包括CPU/Network/IO,通过这些信息可以对自己的数据库性能状况有一个大致的了解. 下面 ...
- 服务器BMC资料整理
1. 现在服务器都有BMC管理了,可以直接连上服务器进行处理. bios里面进行简单设置就可以了, 连接上IPMI的口进行管理. 2. 可以使用 远程控制安装操作系统. 安装系统时 比较清楚的能够看到 ...
- Centos 7搭建Gitlab服务器超详细
一. 安装并配置必要的依赖关系在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问. 1.安装ss ...
- Go基础编程实践(四)—— 数组和map
数组去重 package main import "fmt" func main(){ intSlice := []int{1,5,5,5,5,7,8,6,6, 6} fmt.Pr ...