CentOS 7.4下MySQL 5.7.20主从环境搭建(M(4)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test1 |
+----------------+
1 row in set (0.00 sec)

创建授权账号:slave 指定从服务器IP:10.10.10.72  密码:A@*qw92!derS   

mysql> grant replication slave on *.* to slave@10.10.10.72 identified by "A@*qw92!derS";
Query OK, 0 rows affected, 1 warning (0.00 sec)

步骤五、主从服务器配置:

修改master系统配置文件 /etc/my.cnf  末尾加入 一下内容

log-bin=mysql-bin-master    启用二进制日志

server-id=1     本机数据库ID 标示

binlog-do-db=test  可以被从服务器复制的库, 二进制需要同步的数据库名(创建的测试数据库)

binlog-ignore-db=mysql    不可以被从服务器复制的库

[root@mysqlmaster ~]# systemctl restart mysqld  重启数据库服务器

[root@mysqlmaster ~]# mysql -uroot -p'zX@987Weqqrd1'  登录数据库
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

mysql> show master status;  查看数据库状态信息
+-------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------------+----------+--------------+------------------+-------------------+
| mysql-bin-master.000001 | 154 | test | mysql | |
+-------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> show binlog events\G
*************************** 1. row ***************************
Log_name: mysql-bin-master.000001
Pos: 4
Event_type: Format_desc
Server_id: 1
End_log_pos: 123
Info: Server ver: 5.7.20-log, Binlog ver: 4
*************************** 2. row ***************************
Log_name: mysql-bin-master.000001
Pos: 123
Event_type: Previous_gtids
Server_id: 1
End_log_pos: 154
Info:
2 rows in set (0.00 sec)

如上所示,master服务器已配置成功

mysqldump  -uroot -p'zX@987Weqqrd1' test >test.sql  导出master测试数据库test

[root@mysqlmaster ~]# mysqldump -uroot -p'zX@987Weqqrd1' test >test.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@mysqlmaster ~]# ll test.sql
-rw-r--r-- 1 root root 1790 5月 13 00:01 test.sql

将导出的数据库传到slave服务器上

[root@mysqlmaster ~]# scp test.sql 10.10.10.72:/root
The authenticity of host '10.10.10.72 (10.10.10.72)' can't be established.
ECDSA key fingerprint is SHA256:cHQticA8/IMXFPFXspEnN0h4FLG7LaXnT8Zpr7ricrA.
ECDSA key fingerprint is MD5:1a:70:c5:60:05:47:6a:75:8a:47:db:85:51:1c:32:2c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.72' (ECDSA) to the list of known hosts.
root@10.10.10.72's password:
test.sql 100% 1790 1.9MB/s 00:00

 

配置从服务器

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

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