2.授权用户,用于同步主的数据
mysql> grant replication slave on *.* to 'rep'@'192.168.100.%' identified by '123456'
3.导出主的数据库到当前目录
[root@master ~]# mysqldump -uroot -p123456 --events -A -B --single-transaction --master-data=1 > `date "+F"`-all.sql
4.查看授权用户是否在user表中创建
mysql> select concat_ws('@',user,host) from mysql.user;
+--------------------------+
| concat_ws('@',user,host) |
+--------------------------+
| ping@192.168.100.% |
| rep@192.168.100.% |
| root@ping.cn |
+--------------------------+
5.将内存中的数据刷新到磁盘
mysql> flush privileges;
6.配置从服务器server-id
[root@slave1 ~]# egrep "server-id" /etc/my.cnf
server-id=2
7.配置
mysql> change master to master_host='192.168.100.6', master_user='rep', master_password='123456';
8.将备份的主库文件导入到从服务器中
mysql>source /root/2018-02-26-all.sql
9.开启从服务
mysql>start slave
10.查看从服务状态
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
四、测试
1.删除主服务器数据库
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
2.查看从服务器数据库
mysql> show databases;
+------------------------------+
| Database |
+------------------------------+
| information_schema |
| mysql |
| performance_schema |
+------------------------------+
5 rows in set (0.00 sec)