First, the principle
MySQL master server records the various operations in the binary format into the Bin-log, from the connection master, and read the Bin-log, to achieve data synchronization
Backup: mysqldump-uroot-p 123456 db >1.sql
Import: mysql-uroot-p 123456 db < 1.sql
Ii. Preparatory work
then export the master MySQL library data and then import it to db1
mysqldump-uroot-s/tmp/mysql2.sock mysql > 123.sql;
mysql-uroot-s/tmp/mysql2.sock db1 < 123.sql
< Span style= "font-family: ' Song Body ', Simsun;font-size:13.63636302947998px;line-height:22px;color:rgb (0,0,0); Text-decoration:none; " > Three, configuring
< Span style= "font-family: ' Song Body ', Simsun;font-size:13.63636302947998px;line-height:22px;color:rgb (0,0,0); Text-decoration:none; " >1. Configuring Master master server < Span style= "font-family: ' Song Body ', Simsun;font-size:13.63636302947998px;line-height:22px;color:rgb (0,0,0); Text-decoration:none; " >
(1) Locate the configuration file my.cnf, start the binary file.
Server-id=1 #给数据库服务的唯一标识, typically set to the end of the IP log-bin=mysql-bin #开启二进制日志
(2) Enter MySQL
Set root password: mysqladmin-uroot password ' 123456 ' into database: mysql-uroot-p123456
(3) Create an authorization account, give replication (copy) permission, from server IP to 105
GRANT REPLICATION SLAVE on * * to ' repl ' in ' 192.168.1.105 ' indentified by ' 123456 '
(4) View Log
Mysql>show Master status;
+-------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+-------------------+----------+--------------+------------------+
|master-bin.000001| 1285 | | |
+-------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)
(5) Restart MySQL service
2. Configure slave from the server
(1) Locate the configuration file my.cnf, modify the unique ID
server-id=2
(2) Restart MySQL service
(3) Connect Master
Change Master to master_host= ' 192.168.1.106 ', #master服务器的IP地址master_port =3306,master_user= ' repl ', master_password= ' 123456 ', master_log_file= ' master-bin.000001 ', #master服务器产生的日志master_log_pos = 0;
(4) Start slave
Start slave; (5) Check from the library status show slave status\g; Slave_io_running=yes
MySQL Master copy Build