MySQL Master-Slave principle is very simple, summed up:
Only one master can be set from each. After the master executes the SQL, log the binary log file (Bin-log). From the connection master, and get Binlog from the master, save in local relay-log, and execute SQL from the location you last remembered, and stop synchronizing once an error is encountered.
Judging from these Replication principles, these inferences can be inferred:
Master-slave database is not real-time synchronization, even if the network connection is normal, there is an instant, master-slave data inconsistency. If the master-slave network is disconnected, from the network after normal, batch synchronization. If you modify the data from, then it is very likely from the execution of the main Bin-log error and stop synchronization, this is a very dangerous operation. So in general, be very careful to modify the data from above.
A derivative configuration is a dual-master, mutual primary from the configuration, as long as the two sides of the modification does not conflict, can work well. If you need a multi-master, you can use a ring configuration so that any node changes can be synchronized to all nodes. Can be applied in a read-write separation scenario, to reduce the I/O of a single MySQL server can realize the HA cluster of MySQL service
Can be 1 master multiple from, can also be mutual master and slave (master)
Description: The following document is configured for two MySQL services on the same machine
1. Install and configure Master MySQL
First, refer to the previous steps to build the MySQL service. To make the experiment convenient, we configured two on the same machine
A MySQL service (running two ports).
Tar zxvf mysql-5.1.72-linux-i686-glibc23.tar.gz Decompression
MV Mysql-5.1.72-linux-i686-glibc23/usr/local/mysql Mobile
Useradd-s/sbin/nologin-m MySQL Create user
Cd/usr/local/mysql into the program directory
CP support-files/my-small.cnf/etc/my.cnf Copy configuration file (minimized configuration for experimental use)
CP support-files/mysql.server/etc/init.d/mysqld Copy startup script
Vim/etc/init.d/mysqld Editing a startup script
Modify Basedir and DataDir
Basedir=/usr/local/mysql
Datadir=/data/mysql
Save exit
./scripts/mysql_install_db--user=mysql--datadir=/data/mysql initializing the database directory
There are 2 OK or/data/mysql under whether there are two directories, to prove that the initialization is normal.
At this point, you can start MySQL and use PS or netstat to see if the program starts
2. install the configuration from MySQL
Cp-r/USR/LOCAL/MYSQL/USR/LOCAL/MYSQL2 Copy Main program directory to MYSQL2
CD/USR/LOCAL/MYSQL2 entry from the program directory
CP/ETC/MY.CNF/USR/LOCAL/MYSQL2 copying the master configuration to the Slave directory
VIM/USR/LOCAL/MYSQL2/MY.CNF modifying from a configuration file
Modify the port and socket under [mysqld] and append a datadir in order not to conflict with the primary
Port = 3307
Socket =/tmp/mysql2.sock
DataDir =/data/mysql2
Save exit
./scripts/mysql_install_db--user=mysql--DATADIR=/DATA/MYSQL2 initialization from the database
The end can be started from MySQL, but unlike the main startup script, it needs to be written by itself to start.
Cp/etc/init.d/mysqld/etc/init.d/mysqld2 Copy a startup script
Modify Basedir and DataDir and make my.cnf configuration file paths that differ from the main.
Basedir=/usr/local/mysql2
Datadir=/data/mysql2
Search for my.cnf and modify paths
conf= $basedir/my.cnf or append this line to DATADIR=/DATA/MYSQL2.
Save exit, and then start from program
./MYSQL2 Restart
Then PS and netstat to see if it starts up properly
If you want to configure a third MySQL, follow the configuration from divert.
2.7-mysql Master-slave configuration-1