【MySQL主从复制】

MySQL主从复制

#主设备localhost 从:root2
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
log_bin=mysql-bin
server_id=11#id唯一

[root@root2 ~]# vim /etc/my.cnf
[mysqld]
log_bin=mysql-bin
server_id=12
#修改完之后重启一下mysql

#时间同步
[root@root2 ~]# yum install ntp -y
[root@localhost ~]# ntpdate ntp1.aliyun.com
[root@root2 ~]# ntpdate ntp1.aliyun.com

#创建用户
mysql> grant replication slave on *.* to 'yy'@'192.168.40.%' identified by '密码';

#查看名字及位置
mysql> mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 |      446 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+

#从
mysql>  change master to 
    -> master_host='192.168.40.128',
    -> master_user='yy',
    -> master_password='Fmx1220.',
    -> master_log_file='mysql-bin.000004',
    -> master_log_pos=446;

mysql> start slave;
mysql> show slave status\G;
#均为yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

#主
mysql> create database yy;
Query OK, 1 row affected (0.00 sec)

#从
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| emp                |
| mysql              |
| performance_schema |
| sys                |
| yy                 |
+--------------------+
6 rows in set (0.00 sec)

猜你喜欢

转载自blog.csdn.net/HealerCCX/article/details/131868045