MySQL add non-stop from the library

background

After the primary node line operating for some time, increasing the amount of data, it is necessary to add a node to slave better support business development. However, at this time there is a certain amount of the user, so the master node can not stop, but the slave node is added in the case of non-stop, the specific method is as follows:

surroundings

Firewall and selinux are closed

master slave
IP 192.168.7.71 192.168.7.72
CPU name master01 slave01
THE CentOS7 CentOS7
MySQL version 5.7.28 5.7.28

Steps

1. In the master do a full backup of the database, and to copy the slave node

1.1 View database on the current master
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
1.2 mysqldump full database backup tool
[root@master01 ~]#mysqldump -p -A -F --single-transaction --master-data=1 > /backup/fullbackup_`date +%F_%T`.sql
Enter password: 
[root@master01 ~]#ll /backup/
total 832
-rw-r--r-- 1 root root 849153 Nov 29 20:22 fullbackup_2019-11-29_20:22:04.sql
[root@master01 ~]#scp -p /backup/fullbackup_2019-11-29_20\:22\:04.sql [email protected]:/data/
fullbackup_2019-11-29_20:22:04.sql                   100%  829KB  14.9MB/s   00:00
1.3 Authorization for account creation
grant replication slave on *.* to repluser@'192.168.7.%' identified by '123.com';

Introducing the slave node 2. The master node of the full backup copied

2.1 MySQL installation process slightly
2.2 Add the following to my.cnf file and restart the database.
[mysqld]
server-id = 2
read_only = ON  #设为只读,但是对超级用户无效。
2.3 import and review
[root@slave01 ~]#mysql -p < /data/fullbackup_2019-11-29_20\:22\:04.sql 
Enter password: 
[root@slave01 ~]#mysql -p -e "show databases"
Enter password: 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
We can see already import all libraries on the master node success.

3. Run the following commands in the slave node, the master server specifying information is connected to perform data synchronization.

3.1 full backup of information to find the position
[root@slave01 ~]#grep '^CHANGE MASTER' /data/fullbackup_2019-11-29_20\:22\:04.sql 
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=154;
3.2 connecting the main service configuration information (from the start position after a full backup copy of)
[root@slave01 ~]#mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CHANGE MASTER TO
    ->   MASTER_HOST='192.168.7.71',
    ->   MASTER_USER='repluser',
    ->   MASTER_PASSWORD='123.com',
    ->   MASTER_PORT=3306,
    ->   MASTER_LOG_FILE='mysql-bin.000003',
    ->   MASTER_LOG_POS=154;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
3.3 Starting slave node, and view the synchronization status.
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.7.71
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 154
               Relay_Log_File: slave01-relay-bin.000002
                Relay_Log_Pos: 320
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
...省略信息...

Slave_IO_Running and Slave_SQL_Running threads are Yes, represents the master-slave synchronization is successful, so far, has been achieved online from the library add.

Guess you like

Origin blog.51cto.com/hexiaoshuai/2454909