时间:2021-07-01 10:21:17 帮助过:3人阅读
master端192.168.200.77
1.在/etc/my.cnf里添加
[mysqld]
log-bin=mysql-bin
server-id=1
2.查看设置是否生效
一、在data目录是否有mysql-bin.000001文件和mysql-bin.index文件
二、mysql> show variables like ‘%log_bin%‘;
+---------------------------------+---------------------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------------------+
| log_bin | ON |
| log_bin_basename | /application/mysql/data/mysql_log_bin |
| log_bin_index | /application/mysql/data/mysql_log_bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+---------------------------------------------+
6 rows in set (0.02 sec)
3.添加mysql用户,给slave连接使用
mysql> grant replication slave on *.* to ‘rep‘@‘%‘ identified by ‘oldboy123‘;
mysql> flush privileges;
4.备份主库数据库
1.flush table with read lock;
2.另开一个窗口
mysqldump -uroot -poldboy -A -B --master-data=2 >/tmp/mysql_all_B.sql
可以查看bin-log信息
mysql>show master status;
mysql>show master logs;
3.unlock tables;
#########################################################################
salve端192.168.200.88
1.修改/etc/my.cnf里添加
[mysqld]
server-id=2
2.mysql -uroot -poldboy </tmp/mysql_all_B.sql
3.change master to
master_host=‘192.168.200.77‘,
master_port=3306,
master_user=‘rep‘,
master_password=‘oldboy123‘,
master_log_file=‘mysql_log_bin.000035‘,
master_log_pos=408;
查看cat /application/mysql/data/master.info
4.start slave;
show slave status\G;
Slave_IO_Running:YES
Slave_SQL_Running:YES
有2个YES就说明成功了
在master端插入记录,再到slave端看有没有同步过来
备注:
--master-data=1 适用于从库还原,有change master语句,在slave端使用change master
时可以不用加上master_log_file,master_log_pos语句
--master-data=2 change master语句被注释了
mysql主从复制的步骤
标签:mysql