1.mysql Master-slave replication:
MySQL servers are divided into primary servers for write operations and from servers that are used to replicate the contents of the master server at all times. This allows you to keep multiple server data in sync, so you can do MySQL cluster, which can alleviate the pressure of MySQL server. This speeds up user access.
2.mysql Master-slave replication principle:
1) The primary server establishes a binary log, establishes a binary log (for example, the SQL statement executed, or the disk changes are written in the log)
2) Build Relaylog from the server
3) The master server establishes an authorized account and listens to it from the server.
4) Use the replication account from the server to listen for changes to the master server.
3. Configure the primary server:
1) define a unique ID
Server-id = 1 (This generally prevents duplication, if in an intranet, the last field of IP is not duplicated, you can use this, this is a small trick)
2) prefix of the binary file
Log-bin = Mysql-bin
3) binary format, is the statement, or the disk affects the line to write the log, or mixed (statement row mixed)
Binlog-formate = Mixed
4. From the server configuration:
1) Establish the server ID
Server-id = 2
2) Establish Relay-log
Relay-log = Relay-log
5. The master server establishes an authorized account number: (Note: This can only be *. *, authorized all, not like MongoDB)
Grant replication client,replication Slave on * * to ' replay ' @ ' percent ' identified by ' replay ';
6. Log in to MySQL from the server and then add the Listen Master host
Change Master to
Master_host = ' 115.28.101.251 ',
Master_user = ' Replay ',
Master_password = ' Replay ',
Master_log_file = ' mysql-bin.000022 ', #这个可以从master中查看show master stauts;
Master_log_pos = 1488; #这个也是master中查看 Show Master Status
7. Start slave
Start slave
8. View slave status
Show Slave stauts
#查看mysql主服务器状态
Show master status;
#查看mysql从服务器状态
show slave status;
#重置slave状态
Reset Slave
#启动slave
Start slave
MySQL Master-slave replication