Before the Docker operation, set up the directory, my path is d:/docker/mysql, the directory structure is as follows:
--mysql --master --data --conf --my.cnf --slaver --data --conf --my.cnf
1. master-Slave configuration file
Master:my.cnf
[mysqld]server_id = 1log-bin= mysql-binread-only=0binlog-do-db=bloggingreplicate-ignore-db= mysqlreplicate-ignore-db=sysreplicate-ignore-db=information_schemareplicate-ignore-db=performance_schema! includedir/etc/mysql/conf.d/!includedir/etc/mysql/mysql.conf.d/
Slaver:my.cnf
[mysqld]server_id = 2log-bin= mysql-binread-only=1binlog-do-db=bloggingreplicate-ignore-db= mysqlreplicate-ignore-db=sysreplicate-ignore-db=information_schemareplicate-ignore-db=performance_schema! includedir/etc/mysql/conf.d/!includedir/etc/mysql/mysql.conf.d/
Description
Log-bin: Need to enable binary logging
SERVER_ID: Used to identify different database servers, and unique
BINLOG-DO-DB: Database that needs to be logged to the binary log
BINLOG-IGNORE-DB: Ignoring the database that records the binary log
Auto-increment-offset: The initial value of the server self-increment column
Auto-increment-increment: The server self-incrementing increment
REPLICATE-DO-DB: Specifying the replicated database
REPLICATE-IGNORE-DB: Databases that are not replicated
Relay_log: From the library's trunk log, the main library log is written to the relay log, and the relay log is re-made from the library
Log-slave-updates: Whether to write binary logs from the library, or enable if necessary to become a multi-master. Read-only can not be required
If you are a multi-master, pay attention to setting Auto-increment-offset and Auto-increment-increment
If the above is a double-master setting:
Server 152 self-increment is displayed as: 1,3,5,7,...... (offset=1,increment=2)
Server 153 self-increment is displayed as: 2,4,6,8,...... (offset=2,increment=2)
2. Start creating Master and slave containers
Get the base image Docker pull mysql//Create and start the master-slave container;//masterdocker run--name mastermysql-d-P 3307:3306-e Mysql_root_password=anech- V d:/docker/mysql/master/data:/var/lib/mysql-v d:/docker/mysql/master/conf/my.cnf:/etc/mysql/my.cnf mysql// Slaverdocker run--name slavermysql-d-P 3308:3306-e mysql_root_password=anech-v d:/docker/mysql/slaver/data:/var/lib /mysql-v d:/docker/mysql/slaver/conf/my.cnf:/etc/mysql/my.cnf MySQL
In order to easily view the data, the Docker port is mapped to the native, the corresponding local Master/data folder and the Slaver/data folder can also see the synchronized database files
3. Master and slaver settings
Enter the master container Docker exec-it mastermysql bash//start the MySQL command, just when creating the window we set the password to: anechmysql-u root-p//Create a user to synchronize data grant REPLICATION SLAVE on * * to ' backup ' @ ' percent ' identified by ' 123456 ';
This means creating a slaver synchronization account backup, which allows access to an IP address of%,% for wildcard characters, for example: 192.168.0.% Slaver that represents 192.168.0.0-192.168.0.255 can log on to master with the backup user
Check the status, remember the value of file, position, in slaver will use the show master status;
Enter the Slaver container docker exec-it slavermysql bash//start the MySQL command, just when creating the window we set the password to: Anechmysql-u root-p//set the main library link change master to Master_host= ' 172.17.0.2 ', master_user= ' backup ', master_password= ' 123456 ', master_log_file= ' mysql-bin.000001 ', master_log_pos=0,master_port=3306;//start sync from library start slave;//view status of Show slaver status;
Description
Master_host: Main Library Address
Master_user: Sync account created by the main library
Master_password: Sync password created by the main library
Master_log_file: Log generated by the main library
Master_log_pos: Main Library log record offset
Master_port: Port used by the main library, default is 3306
Reference: http://blog.csdn.net/kk185800961/article/details/49235975
http://blog.csdn.net/qq362228416/article/details/48569293
Http://www.cnblogs.com/alvin_xp/p/4162249.html
Article Source: http://www.cnblogs.com/anech/p/6721746.html
Reprint Please note name source, thank you!
Docker MySQL master-Slave synchronization configuration Build Demo