Linux下MySQL数据库主从同步配置(2)

show variables like 'server_id';#看到id为2,表示正常
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id    | 2    |
+---------------+-------+
1 row in set (0.00 sec)

slave stop;#停止slave同步进程

change master to master_host='172.30.65.122',master_user='cesudbbak',master_password='123456',master_log_file='mysql-bin.000006',master_log_pos=106;#执行同步语句,master_log_file和master_log_pos就是上面提到的那连个值
mysql> change master to master_host='172.30.65.122',master_user='cesudbbak',master_password='123456',master_log_file='mysql-bin.000006',master_log_pos=106;
Query OK, 0 rows affected (0.02 sec)

slave start;#开启slave同步进程

SHOW SLAVE STATUS\G#查看同步信息,会出现以下的同步信息
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
              Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.30.65.122
                  Master_User: cesudbbak
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000006
          Read_Master_Log_Pos: 106
              Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000006
            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: cesudb
          Replicate_Ignore_DB: mysql
          Replicate_Do_Table:
      Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                  Last_Errno: 0
                  Last_Error:
                Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 407
              Until_Condition: None
              Until_Log_File:
                Until_Log_Pos: 0
          Master_SSL_Allowed: No
          Master_SSL_CA_File:
          Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
              Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
              Last_SQL_Errno: 0
              Last_SQL_Error:
1 row in set (0.00 sec)
注意出现红色字体的部分,以上的连个参数出现yes代表配置成功。

五.测试主从配置

1.在主数据库上建立一个表student#172.30.65.122
mysql -u root -p

use cesudb;

create table ...#建一个测试表
mysql> create table student (
    -> id int,
    -> name char(10),
    -> sex char(2));
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+------------------+
| Tables_in_cesudb |
+------------------+
| student          |
+------------------+
1 row in set (0.00 sec)

2.登录从数据库查看该表#172.30.65.124

mysql> use cesudb
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_cesudb |
+------------------+
| student          |
+------------------+
1 row in set (0.00 sec)

已经自动同步过来,说明同步成功。

实现两个MySQL数据库之间的主从同步

Linux环境中MySQL主从同步--添加新的从库

通过 XtraBackup 实现不停机不锁表搭建MySQL主从同步

MySQL主从同步配置记录

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/9efe7eaa7bb79627e9789222fe464924.html