MySql 之 Binglog 复制

news2024/12/23 10:09:41

     复制是一种将数据从一个 MySQL 数据库服务器异步复制到另一个的技术。使用 MySQL 复制选项,您可以复制所有数据库、选定的数据库甚至选定的表,具体取决于您的使用情况。

前提条件

  • 确保在源服务器上启用了二进制日志记录。
  • 确保复制配置中的所有服务器都有唯一的服务器 ID(不能重复)。
  • 确保复制配置中的所有服务器都有唯一的 UUID(不能重复)。
  • 为复制创建一个单独的用户,以便对源进行身份验证,读取复制的二进制日志。

检查MySQL状态

[root@mysql-a ~]# systemctl status mysqld

配置参数

     更改配置文件,加入 binlog 复制所需的 MySQL 复制参数。停止 MySQL 守护进程,编辑 /etc/my.cnf 文件以包含参数,然后启动 MySQL 守护进程。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
[root@mysql-a ~]# systemctl stop mysqld
[root@mysql-a ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-a ~]#
[root@mysql-a ~]# vi /etc/my.cnf
[root@mysql-a ~]# cat /etc/my.cnf
[mysqld]
# MySQL Replication parameters
log-bin=mysql-bin
log-bin-index=mysql-bin.index
server-id=1
binlog-format=ROW
innodb-flush-log-at-trx-commit=1
sync-binlog=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-a ~]#
[root@mysql-a ~]# systemctl start mysqld
>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
[root@mysql-b ~]# systemctl stop mysqld
[root@mysql-b ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-b ~]#
[root@mysql-b ~]# vi /etc/my.cnf
[root@mysql-b ~]# cat /etc/my.cnf
[mysqld]
# MySQL Replication parameters
server-id=2
relay-log=relay-mysql-b
relay-log-index=relay-mysql-b.index
skip-slave-start
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-b ~]#
[root@mysql-b ~]# systemctl start mysqld
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
[root@mysql-c ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-c ~]#
[root@mysql-c ~]# systemctl stop mysqld
[root@mysql-c ~]# vi /etc/my.cnf
[root@mysql-c ~]# cat /etc/my.cnf
[mysqld]
server-id=3
relay-log=relay-mysql-c
relay-log-index=relay-mysql-c.index
skip-slave-start
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-c ~]#
[root@mysql-c ~]# systemctl start mysqld

注意 复制配置中的每台服务器的 server-id 都应不同。

SKIP_NETWORKING

确保将 SKIP_NETWORKING 变量设置为 OFF。如果设置为 ON,副本就无法与源进行通信。在所有三个服务器(mysql-a、mysql-b 和 mysql-c)上使用以下示例参考进行设置:

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
[root@mysql-a ~]# su - mysql
Last login: Wed Sep 13 22:23:01 CDT 2023 on pts/0
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> show variables like 'skip_networking';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| skip_networking | OFF   |
+-----------------+-------+
1 row in set (0.02 sec)

创建用户

创建名为 replication_user 的用户,用于从源复制到每个副本,并授予复制从属权限。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> create user 'replication_user'@'192.168.2.20' identified by 'WElcome_1234#';
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to 'replication_user'@'192.168.2.20';
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'replication_user'@'192.168.2.25' identified by 'WElcome_1234#';
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to 'replication_user'@'192.168.2.25';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------------------+--------------+
| user             | host         |
+------------------+--------------+
| replication_user | 192.168.2.20 |
| replication_user | 192.168.2.25 |
| mysql.infoschema | localhost    |
| mysql.session    | localhost    |
| mysql.sys        | localhost    |
| root             | localhost    |
+------------------+--------------+
6 rows in set (0.00 sec)

获取主MySQL的binlog信息

从主MySQL获取二进制日志坐标。在此之前,请先获取读锁定。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
|File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set  |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |  1482    |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

记下 binlog 文件名和 binlog 位置,以便以后在副本上配置复制源时使用。

已有数据的备份(源MySQL)

根据使用情况创建数据快照。您可以选择复制所有现有数据或数据子集。在本例中,我们将使用 --all-databases 参数复制所有现有数据以及触发器、例程和事件。逻辑备份完成后,解锁表。使用 mysqldump 进行逻辑备份。逻辑备份名为 replication_db_dump.db。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
-bash-4.2$ mysqldump -uroot -p --all-databases --triggers --routines --events --source-data --set-gtid-purged=OFF > replication_db_dump.db
Enter password:
-bash-4.2$ ls -ltr
total 1256
-rw-rw-r-- 1 mysql mysql 1283914 Oct  6 10:46 replication_db_dump.db
-bash-4.2$
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

恢复数据(副本MySQL)

复制源服务器 (mysql-a) 上的逻辑备份,并将其导入副本服务器 (mysql-b 和 mysql-c)。在下面的示例中,我们将逻辑备份 replication_db_dump.db 复制到 mysql-b 和 mysql-c。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
-bash-4.2$ ls -ltr
total 1256
-rw-rw-r-- 1 mysql mysql 1283914 Oct  6 10:46 replication_db_dump.db
-bash-4.2$ scp -r replication_db_dump.db 192.168.2.20:/home/mysql/.
The authenticity of host '192.168.2.20 (192.168.2.20)' can't be established.
ECDSA key fingerprint is SHA256:YpDYEJtpp16FvKQ/X2muJuFwk0iL9YG2fRJWnQLaxGE.
ECDSA key fingerprint is MD5:77:b3:32:b9:5f:74:27:6d:df:1c:0f:c9:76:16:7c:cb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.20' (ECDSA) to the list of known hosts.
mysql@192.168.2.20's password:
replication_db_dump.db                 100% 1254KB  73.0MB/s   00:00
-bash-4.2$
-bash-4.2$ scp -r replication_db_dump.db 192.168.2.25:/home/mysql/.
The authenticity of host '192.168.2.25 (192.168.2.25)' can't be established.
ECDSA key fingerprint is SHA256:YpDYEJtpp16FvKQ/X2muJuFwk0iL9YG2fRJWnQLaxGE.
ECDSA key fingerprint is MD5:77:b3:32:b9:5f:74:27:6d:df:1c:0f:c9:76:16:7c:cb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.25' (ECDSA) to the list of known hosts.
mysql@192.168.2.25's password:
replication_db_dump.db                 100% 1254KB  73.0MB/s   00:00
-bash-4.2$
>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
-bash-4.2$ ls -ltr
total 1256
-rw-r--r-- 1 mysql mysql 1283914 Oct  6 10:53 replication_db_dump.db
-bash-4.2$
-bash-4.2$ mysql -uroot -p < replication_db_dump.db
Enter password:
-bash-4.2$
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
-bash-4.2$ ls -ltr
total 1256
-rw-r--r-- 1 mysql mysql 1283914 Oct  6 10:53 replication_db_dump.db
-bash-4.2$
-bash-4.2$ mysql -uroot -p < replication_db_dump.db
Enter password:

校验配置

验证复制配置(mysql-a、mysql-b、mysql-c)中每台服务器的服务器 ID 是否不同,并确保每台服务器都有不同的 UUID。如果服务器 UUID 相同,请使用以下步骤修改服务器 UUID:

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|          1  |
+-------------+
1 row in set (0.00 sec)
mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| d763ea33-52ad-11ee-84a8-080027cf69cc |
+--------------------------------------+
1 row in set (0.00 sec)
>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|          2  |
+-------------+
1 row in set (0.00 sec)
mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| d763ea33-52ad-11ee-84a8-080027cf69cc |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
-bash-4.2$ exit
logout
[root@mysql-b ~]# systemctl stop mysqld
[root@mysql-b ~]# cd /var/lib/mysql
[root@mysql-b mysql]# ls -ltr *auto*
-rw-r----- 1 mysql mysql 56 Sep 13 22:21 auto.cnf
[root@mysql-b mysql]#
[root@mysql-b mysql]# mv auto.cnf /tmp/.
[root@mysql-b mysql]#
[root@mysql-b mysql]# ls -ltr *auto*
ls: cannot access *auto*: No such file or directory
[root@mysql-b mysql]#
[root@mysql-b mysql]# systemctl start mysqld
[root@mysql-b mysql]#
[root@mysql-b mysql]# ls -ltr *auto*
-rw-r----- 1 mysql mysql 56 Oct  6 11:04 auto.cnf
[root@mysql-b mysql]#
[root@mysql-b mysql]# cat auto.cnf
[auto]
server-uuid=1169b107-6462-11ee-b802-080027cf69cc
[root@mysql-b mysql]#
>>> Notice a new UUID is generated
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|          3  |
+-------------+
1 row in set (0.00 sec)
mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| d763ea33-52ad-11ee-84a8-080027cf69cc |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
-bash-4.2$ exit
logout
[root@mysql-c ~]# systemctl stop mysqld
[root@mysql-c ~]# ls -ltr /var/lib/mysql/auto.cnf
-rw-r----- 1 mysql mysql 56 Sep 13 22:21 /var/lib/mysql/auto.cnf
[root@mysql-c ~]#
[root@mysql-c ~]# mv /var/lib/mysql/auto.cnf /tmp/.
[root@mysql-c ~]#
[root@mysql-c ~]# ls -ltr /var/lib/mysql/auto.cnf
ls: cannot access /var/lib/mysql/auto.cnf: No such file or directory
[root@mysql-c ~]#
[root@mysql-c ~]# systemctl start mysqld
[root@mysql-c ~]# ls -ltr /var/lib/mysql/auto.cnf
-rw-r----- 1 mysql mysql 56 Oct  6 11:07 /var/lib/mysql/auto.cnf
[root@mysql-c ~]#
[root@mysql-c ~]# cat /var/lib/mysql/auto.cnf
[auto]
server-uuid=832d4368-6462-11ee-bcb2-080027cf69cc

副本服务器的配置

在副本上配置必须从哪个复制源复制数据,以及必须从哪个 binlog 文件和位置开始复制。从之前步骤 获取 binlog 文件名和文件位置。

>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> CHANGE REPLICATION SOURCE TO
    -> SOURCE_HOST='192.168.2.15',
    -> SOURCE_USER='replication_user',
    -> SOURCE_PASSWORD='WElcome_1234#',
    -> SOURCE_LOG_FILE='mysql-bin.000001',
    -> SOURCE_LOG_POS=1482,
    -> GET_SOURCE_PUBLIC_KEY=1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> show replica status\G;
*************************** 1. row ***************************
             Replica_IO_State:
                  Source_Host: 192.168.2.15
                  Source_User: replication_user
                  Source_Port: 3306
                Connect_Retry: 60
              Source_Log_File: mysql-bin.000001
          Read_Source_Log_Pos: 1482
               Relay_Log_File: relay-mysql-b.000001
                Relay_Log_Pos: 4
        Relay_Source_Log_File: mysql-bin.000001
           Replica_IO_Running: No
          Replica_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Source_Log_Pos: 1482
              Relay_Log_Space: 157
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Source_SSL_Allowed: No
           Source_SSL_CA_File:
           Source_SSL_CA_Path:
              Source_SSL_Cert:
            Source_SSL_Cipher:
               Source_SSL_Key:
        Seconds_Behind_Source: NULL
Source_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Source_Server_Id: 0
                  Source_UUID:
             Source_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
    Replica_SQL_Running_State:
           Source_Retry_Count: 86400
                  Source_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Source_SSL_Crl:
           Source_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Source_TLS_Version:
       Source_public_key_path:
        Get_Source_public_key: 1
            Network_Namespace:
1 row in set (0.00 sec)
ERROR:
No query specified
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> CHANGE REPLICATION SOURCE TO
    -> SOURCE_HOST='192.168.2.15',
    -> SOURCE_USER='replication_user',
    -> SOURCE_PASSWORD='WElcome_1234#',
    -> SOURCE_LOG_FILE='mysql-bin.000001',
    -> SOURCE_LOG_POS=1482,
    -> GET_SOURCE_PUBLIC_KEY=1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> show replica status\G;
*************************** 1. row ***************************
             Replica_IO_State:
                  Source_Host: 192.168.2.15
                  Source_User: replication_user
                  Source_Port: 3306
                Connect_Retry: 60
              Source_Log_File: mysql-bin.000001
          Read_Source_Log_Pos: 1482
               Relay_Log_File: relay-mysql-c.000001
                Relay_Log_Pos: 4
        Relay_Source_Log_File: mysql-bin.000001
           Replica_IO_Running: No
          Replica_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Source_Log_Pos: 1482
              Relay_Log_Space: 157
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Source_SSL_Allowed: No
           Source_SSL_CA_File:
           Source_SSL_CA_Path:
              Source_SSL_Cert:
            Source_SSL_Cipher:
               Source_SSL_Key:
        Seconds_Behind_Source: NULL
Source_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Source_Server_Id: 0
                  Source_UUID:
             Source_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
    Replica_SQL_Running_State:
           Source_Retry_Count: 86400
                  Source_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Source_SSL_Crl:
           Source_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Source_TLS_Version:
       Source_public_key_path:
        Get_Source_public_key: 1
            Network_Namespace:
1 row in set (0.00 sec)
ERROR:
No query specified

开始复制

在每个复制服务器上发布启动复制语句,开始复制。

>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
-bash-4.2$ hostname
mysql-b
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> start replica;
Query OK, 0 rows affected (0.01 sec)
mysql> show replica status\G;
*************************** 1. row ***************************
             Replica_IO_State: Waiting for source to send event
                  Source_Host: 192.168.2.15
                  Source_User: replication_user
                  Source_Port: 3306
                Connect_Retry: 60
              Source_Log_File: mysql-bin.000001
          Read_Source_Log_Pos: 1482
               Relay_Log_File: relay-mysql-b.000002
                Relay_Log_Pos: 326
        Relay_Source_Log_File: mysql-bin.000001
           Replica_IO_Running: Yes
          Replica_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Source_Log_Pos: 1482
              Relay_Log_Space: 534
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Source_SSL_Allowed: No
           Source_SSL_CA_File:
           Source_SSL_CA_Path:
              Source_SSL_Cert:
            Source_SSL_Cipher:
               Source_SSL_Key:
        Seconds_Behind_Source: 0
Source_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Source_Server_Id: 1
                  Source_UUID: d763ea33-52ad-11ee-84a8-080027cf69cc
             Source_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
    Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Source_Retry_Count: 86400
                  Source_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Source_SSL_Crl:
           Source_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Source_TLS_Version:
       Source_public_key_path:
        Get_Source_public_key: 1
            Network_Namespace:
1 row in set (0.00 sec)
ERROR:
No query specified
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
-bash-4.2$ hostname
mysql-c
-bash-4.2$ mysql -u root -p
Enter password:
mysql> start replica;
Query OK, 0 rows affected (0.02 sec)
mysql> show replica status\G;
*************************** 1. row ***************************
             Replica_IO_State: Waiting for source to send event
                  Source_Host: 192.168.2.15
                  Source_User: replication_user
                  Source_Port: 3306
                Connect_Retry: 60
              Source_Log_File: mysql-bin.000001
          Read_Source_Log_Pos: 1482
               Relay_Log_File: relay-mysql-c.000002
                Relay_Log_Pos: 326
        Relay_Source_Log_File: mysql-bin.000001
           Replica_IO_Running: Yes
          Replica_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Source_Log_Pos: 1482
              Relay_Log_Space: 534
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Source_SSL_Allowed: No
           Source_SSL_CA_File:
           Source_SSL_CA_Path:
              Source_SSL_Cert:
            Source_SSL_Cipher:
               Source_SSL_Key:
        Seconds_Behind_Source: 0
Source_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Source_Server_Id: 1
                  Source_UUID: d763ea33-52ad-11ee-84a8-080027cf69cc
             Source_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
    Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Source_Retry_Count: 86400
                  Source_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Source_SSL_Crl:
           Source_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Source_TLS_Version:
       Source_public_key_path:
        Get_Source_public_key: 1
            Network_Namespace:
1 row in set (0.00 sec)
ERROR:

测试

在源 mysql-a 中创建几个数据库和表,并验证它们是否复制到了副本 mysql-b 和 mysql-c。

>>>>>>>>>>>>>>>>> mysql-a <<<<<<<<<<<<<<<<
-bash-4.2$ hostname
mysql-a
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| mysql               |
| performance_schema  |
| sys                 |
+---------------------+
4 rows in set (0.00 sec)
mysql> create database db1;
Query OK, 1 row affected (0.01 sec)
mysql> create database db2;
Query OK, 1 row affected (0.01 sec)
mysql> create database db3;
Query OK, 1 row affected (0.00 sec)
mysql> use db1;
Database changed
mysql> create table tab1 (no int);
Query OK, 0 rows affected (0.02 sec)
mysql> create table tab2 (no int);
Query OK, 0 rows affected (0.01 sec)
mysql> create table tab3 (no int);
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| tab1          |
| tab2          |
| tab3          |
+---------------+
3 rows in set (0.00 sec)
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| db1                 |
| db2                 |
| db3                 |
| information_schema  |
| mysql               |
| performance_schema  |
| sys                 |
+---------------------+
7 rows in set (0.00 sec)
>>>>>>>>>>>>>>>>> mysql-b <<<<<<<<<<<<<<<<
-bash-4.2$ hostname
mysql-b
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| db1                 |
| db2                 |
| db3                 |
| information_schema  |
| mysql               |
| performance_schema  |
| sys                 |
+---------------------+
7 rows in set (0.00 sec)
mysql> use db1;
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
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| tab1          |
| tab2          |
| tab3          |
+---------------+
3 rows in set (0.00 sec)
>>>>>>>>>>>>>>>>> mysql-c <<<<<<<<<<<<<<<<
-bash-4.2$ hostname
mysql-c
-bash-4.2$ mysql -uroot -p
Enter password:
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| db1                 |
| db2                 |
| db3                 |
| information_schema  |
| mysql               |
| performance_schema  |
| sys                 |
+---------------------+
7 rows in set (0.00 sec)
mysql> use db1;
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
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| tab1          |
| tab2          |
| tab3          |
+---------------+
3 rows in set (0.00 sec)

以上便是基于binlog复制的步骤,需要注意的时,以上是基于MySQL 8.0.24及以上版本的!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2201033.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

《云原生安全攻防》-- K8s攻击案例:从Pod容器逃逸到K8s权限提升

在本节课程中&#xff0c;我们将介绍一个完整K8s攻击链路的案例&#xff0c;其中包括了从web入侵到容器逃逸&#xff0c;再到K8s权限提升的过程。通过以攻击者的视角&#xff0c;可以更全面地了解K8s环境中常见的攻击技术。 在这个课程中&#xff0c;我们将学习以下内容&#…

使用 Go 和 Gin 框架构建简单的用户和物品管理 Web 服务

使用 Go 和 Gin 框架构建简单的用户和物品管理 Web 服务 在本项目中&#xff0c;我们使用 Go 语言和 Gin 框架构建了一个简单的 Web 服务&#xff0c;能够管理用户和物品的信息。该服务实现了两个主要接口&#xff1a;根据用户 ID 获取用户名称&#xff0c;以及根据物品 ID 获…

spring boot itext7的生成一个pdf(hello,world),并且相关一些简单的使用方法及相关说明

1、我们经常会碰到生成Pdf的场景&#xff0c;比如说有很多题目&#xff0c;又比如说来个质检的报告&#xff0c;我们都需要导出为pdf&#xff0c;那这种情况有二种方法&#xff0c;一种是通过报表来实现&#xff0c;一种就是通过itext来生成。一般我们会通过报表来直接导出pdf。…

Liquid AI与液态神经网络:超越Transformer的大模型架构探索

1. 引言 自2017年谷歌发表了开创性的论文《Attention Is All You Need》以来&#xff0c;基于Transformer架构的模型迅速成为深度学习领域的主流选择。然而&#xff0c;随着技术的发展&#xff0c;挑战Transformer主导地位的呼声也逐渐高涨。最近&#xff0c;由麻省理工学院(M…

简述何为多态

1.多态的概念 多态是什么?首先我们从概念讲起,简单来讲,多态就是多种形态,当你要去完成同一件事情的时候,不同的人去完成这件事情会有不同的结果. 比如在买票的时候,如果是成人去买票,则会买到成人票;如果是学生,则会买到学生票. 2.多态的实现以及构成条件 首先,多态的实现…

【Flutter、Web——前端个人总结】分享从业经历经验、自我规范准则,纯干货

前言 hi&#xff0c;正式接触web前端已经经过了两年的时间&#xff0c;从大学的java后端转型到web前端&#xff0c;再到后续转战Flutter&#xff0c;逐渐对前端有了一些心得体会&#xff0c;其实在当下前端的呈现形式一直在变化&#xff0c;无论你是用原生、还是web还是混编的…

Django 1.2标准日志模块出现奇怪行为时的解决方案

在 Django 1.2 中&#xff0c;标准日志模块有时会出现意想不到的行为&#xff0c;例如日志消息未按预期记录、日志级别未正确应用或日志格式错乱等。这些问题可能源于日志配置不当、日志模块被多次初始化、或日志模块被其他包覆盖等原因。下面是一些常见问题的排查方法和解决方…

力扣21~25题

21题&#xff08;简单&#xff09;&#xff1a; 分析&#xff1a; 按要求照做就好了&#xff0c;这种链表基本操作适合用c写&#xff0c;python用起来真的很奇怪 python代码&#xff1a; # Definition for singly-linked list. # class ListNode: # def __init__(self, v…

二、MySQL的数据目录

文章目录 1. MySQL8的主要目录结构1.1 数据库文件的存放路径1.2 相关命令目录1.3 配置文件目录 2. 数据库和文件系统的关系2.1 查看默认数据库2.2 数据库在文件系统中的表示2.3 表在文件系统中的表示2.3.1 InnoDB存储引擎模式2.3.2 MyISAM存储引擎模式 2.4 小结 1. MySQL8的主要…

宝塔docker中如何修改应用配置文件参数

今天在宝塔docker安装了kkfileview&#xff0c;相修改应用里的application.properties&#xff0c;却找不到在哪&#xff0c;如何修改&#xff1f; 下面教大家应用找文件修改。 docker安装好对应容器后&#xff0c;是这样 在这里是找不到对应修改的地方&#xff0c;其实docker…

Linux WIFI 驱动实验

直接参考【正点原子】I.MX6U嵌入式Linux驱动开发指南V1.81 本文仅作为个人笔记使用&#xff0c;方便进一步记录自己的实践总结。 WIFI 的使用已经很常见了&#xff0c;手机、平板、汽车等等&#xff0c;虽然可以使用有线网络&#xff0c;但是有时候很多设备存在布线困难的情况&…

Windows10的MinGW安装和VS Code配置C/C++编译环境

1. MinGW下载安装 首先需要说明的是VS Code是一个编辑器&#xff0c;而不是编译器。‌ 编辑器和编译器是有很明显的区别 1.1 编辑器和编译器区别 编辑器‌是一种用于编写和编辑文本的应用软件&#xff0c;主要用于编写程序的源代码。编辑器提供基本的文本编辑功能&#xff0c;…

面试题:Redis(三)

1. 面试题 背景 问题&#xff0c;上面业务逻辑你用java代码如何写&#xff1f; 2. 缓存双写一致性谈谈你的理解&#xff1f; 3. 双检加锁策略 多个线程同时去查询数据库的这条数据&#xff0c;那么我们可以在第一个查询数据的请求上使用一个 互斥锁来锁住它。 其他的线程走到这…

内核编译 设备驱动 驱动程序

内核编译 一、内核编译的步骤 编译步骤&#xff1a; (linux 内核源码的顶层目录下操作 ) 1. 拷贝默认配置到 .config cp config_mini2440_td35 .config 2. make menuconfig 内核配置 make menuconfig 3. make uImage make u…

docker-compose无法切换用户

问题描述 jupyter:image: flink:1.19-pyprivileged: trueuser: rootports:- "9999:8888"volumes:- /data/docker_data/jupyter:/workcommand: sh -c "cd / && jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root --NotebookApp.passwordsha1:658…

循环神经网络-LSTM网络

文章目录 前言一、LSTM网络简介二、LSTM的门结构1.遗忘门2.输入门3.输出门 三、总结 前言 循环神经网络&#xff08;Recurrent Neural Networks&#xff0c;RNN&#xff09;是一种特殊的神经网络&#xff0c;具有能够处理序列数据的能力&#xff0c;然而&#xff0c;RNN在处理…

团员申请书怎么写?这里归纳了一些模板

团员申请书怎么写&#xff1f;随着社会的快速发展和时代的进步&#xff0c;越来越多的青年人意识到加入团组织的重要性。作为新时代的青年&#xff0c;我们应当积极响应国家的号召&#xff0c;参与到团组织的建设中来。而想要成为共青团员&#xff0c;首先需要撰写一份规范的团…

新手一次过软考高级(系统架构设计师)秘笈,请收藏!

软考系统架构设计师是高级科目之一&#xff0c;也是比较有难度的科目&#xff0c;但是只要你把该掌握的知识掌握熟练&#xff0c;技能水平达到要求&#xff0c;那还是考可以拿下证书的。 系统架构设计师适合人群&#xff1a;适合熟悉开发过程与方法、数据库、信息安全的技术人员…

NLP: SBERT介绍及sentence-transformers库的使用

1. Sentence-BERT Sentence-BERT(简写SBERT)模型是BERT模型最有趣的变体之一&#xff0c;通过扩展预训练的BERT模型来获得固定长度的句子特征&#xff0c;主要用于句子对分类、计算两个句子之间的相似度任务。 1.1 计算句子特征 SBERT模型同样是将句子标记送入预训练的BERT模型…

OmniH2O——通用灵巧且可全身远程操作并学习的人形机器人(其前身H2O是HumanPlus的重要参考)

前言 由于我司一直在针对各个工厂、公司、客户特定的业务场景&#xff0c;做解决方案或定制开发&#xff0c;所以针对每一个场景&#xff0c;我们都会反复考虑用什么样的机器人做定制开发 于此&#xff0c;便不可避免的追踪国内外最前沿的机器人技术进展&#xff0c;本来准备…