Environment Preparation:
Deploy a master one from two servers, achieve master-slave replication, the main library to open Binlog, the main library and the Server-id from the library to be different
Main Library:
[Email protected] ~]# hostname-i
10.0.0.51 172.16.1.51
[Email protected] ~]# egrep "Log_bin|server-id"/etc/my.cnf
Server-id = 1 #主库的Server-id
Log_bin = Mysql-bin #开启binlog
From library:
[Email protected] ~]# hostname-i
10.0.0.52 172.16.1.52
[Email protected] ~]# egrep "Server-id"/etc/my.cnf
Server-id = 2 #从库的Server-id
Main Library Operations:
1, create the user, for the master-slave connection
mysql> grant replication Slave on * * to ' rep ' @ ' 172.16.1.% ' identified by ' 123456 ';
mysql> flush Privileges;
Mysql> select User,host from Mysql.user;
2, lock table, prohibit writing data
Mysql> Flush table with read lock;
3. Open a new window to export the main library data
[Email protected] ~]# Mysqldump-a-B--master-data=2 >/opt/3306.sql
4, unlock, open user Write function
mysql> unlock tables;
5. Copy the backup data from the main library to the library
[Email protected] ~]# Scp/opt/3306.sql 172.16.1.52:/opt/
From library operations:
1. Import the master library to the Slave library
[[email protected] ~]# MySQL </opt/3306.sql
2, find Binlog location point
[Email protected] ~]# sed-n ' 22p '/opt/3306.sql
--Change MASTER to master_log_file= ' oldboy-bin.000010 ', master_log_pos=405;
3, Configuration Master.info
Change MASTER to
Master_host= ' 172.16.1.51 ',
master_port=3306,
Master_user= ' rep ',
Master_password= ' oldboy123 ',
Master_log_file= ' mysql-bin.000010 ',
master_log_pos=405;
4. Turn on the sync function to view the status
mysql> start slave;
Mysql> Show Slave Status\g
The following status information appears indicating that the master-slave replication configuration was successful
Slave_io_running:yes
Slave_sql_running:yes
seconds_behind_master:0
This article from the "12206254" blog, reproduced please contact the author!
MySQL master-slave replication deployment process