mysql 主从备份

1.1、环境准备

两台机器ip分别为

100.100.100.105 (主)
100.100.100.106(从)

安装 mysql

[root@centos ~]# yum install mysql-server mysql-client -y
[root@centos ~]# service mysqld start
[root@centos ~]# /usr/bin/mysqladmin -u root password '123456'
1.2、修改配置文件
100.100.100.105
[root@centos ~]# vim /etc/my.cnf
log-bin=mysql-bin
server-id=105
100.100.100.106
[root@centos ~]# vim /etc/my.cnf
log-bin=mysql-bin
server-id=106
1.3、添加mysql用户
mysql> grant replication slave on *.* to slave@'100.100.100.106' identified by '123456';
1.4、查看主服务器信息
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |      261 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
1.5、登录从mysql
change master to
master_user='slave',
master_password='123456',
master_host='100.100.100.105',
master_log_file='mysql-bin.000004',
master_log_pos=261;
1.6、开启从mysql
mysql> start slave;

1.7、判断成功,可查看如下参数
mysql> show slave status\G;
            Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
posted @ 2020-01-16 13:04  叶落西南  阅读(112)  评论(0编辑  收藏  举报