The master-slave configuration of the MySQL server is a very simple task. Instead of starting from scratch, it is always on the MySQL server that has been installed by others. This will involve the mysql version, startup File and other issues.
But it doesn't matter. Let's clarify two points first.
1. MySQL configuration file my. CNF location
2. How to start and stop MySQL and find the Startup File
Suppose there are two machines and MySQL has been installed (try to use the same version, and the two machines have the same network, you can ping)
A friend said, "The slave server cannot be lower than the master server version." However, I am lower than the master server version and there is no problem.
Host a: 192.168.1.100
Slave B: 192.168.1.101
Multiple slave servers
1. log on to host a first.
Mysql> grant replication slave on *. * To 'backup '@ '192. 168.220.135' identified by '123 ';
Grant permissions to the slave machine. If multiple slave machines exist, the slave machine is executed multiple times.
2. Open My. CNF of host a and enter
Server-id = 1 # host ID, integer
Log_bin =/var/log/MySQL/mysql-bin.log # Make sure this file is writable
Read-Only = 0 # host, both read and write are allowed
BINLOG-do-DB = test # You need to back up data and write multiple rows.
BINLOG-ignore-DB = MySQL # databases that do not need to be backed up, multiple write lines
3. Open My. CNF of slave machine B and enter
Server-id = 2
Log_bin =/var/log/MySQL/mysql-bin.log
Master-host = 192.168.1.100
Master-user = backup
Master-pass = 123456
Master-Port = 3306
Master-connect-retry = 60 # Time Difference (in seconds) when the master server is disconnected from the server)
Replicate-do-DB = test # only copy a database
Replicate-ignore-DB = MySQL # do not copy a database
4. Synchronize Databases
There are multiple ways to export the data test of host a to test. SQL first.
Then, create the database test from machine B. MySQL imports test. SQL to the database test.
5. Restart MySQL of host a and MySQL of slave B.
6. Verification
In host a, mysql> show Master Status \ G;
In slave machine B, mysql> show slave status \ G;
You can see the following content:
File: mysql-bin.000001
Position: 1374
Binlog_do_db: Test
Binlog_ignore_db: MySQL
You can perform insert, update, and delete operations in host a to check whether the operation has been modified in host B.
Some other friends wrote the following, and I have made some reference.
Http://www.ningoo.net/html/2007/mysql_replication_configuration.html
Http://leftleg.hzpub.com/post/645/
Http://blog.zhangjianfeng.com/article/705