Docker MySQL master-slave configuration detailed and examples _mysql

Source: Internet
Author: User
Tags reserved docker run

Docker MySQL master-slave configuration

1, first create two file my-m.cnf (main library configuration), MY-S.CNF (from the library configuration)

MY-M.CNF content is as follows

# Copyright (c) 2014, Oracle and/or its affiliates.
All rights reserved. # this are free software; Can redistribute it and/or modify # it under the terms of the GNU general public License as published Ftware Foundation;
Version 2 of the License. # This is distributed to the hope that it'll be useful, # but without any WARRANTY; Without even the implied warranty of # merchantability or FITNESS for A particular purpose.
The # GNU general public License for more details. # Your should have received a copy of the GNU general public, License # along with this program; If not, write to the free Software # Foundation, INC, Wuyi Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # The MyS
QL Community Server configuration file.   # for explanations # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [client] port = 3306 socket =/var/run/mysqld/mysqld.sock [Mysqld_safe] pid-file =/var/run/mysqld/mysqld.pid socket =/vaR/run/mysqld/mysqld.sock nice = 0 [mysqld] user = MySQL Pid-file =/var/run/mysqld/mysqld.pid socket =/var/run/ Mysqld/mysqld.sock Port = 3306 basedir =/usr DataDir =/var/lib/mysql tmpdir =/tmp Lc-messages-dir =/usr/share /mysql Explicit_defaults_for_timestamp log-bin = Mysql-bin Server-id = 1 # Instead of skip-networking the ' default is n
ow to listen only on # localhost which are more compatible and are not less secure. #bind-address = 127.0.0.1 #log-error =/var/log/mysql/error.log # recommended in standard MySQL setup Sql_mode=no_engin E_substitution,strict_trans_tables # Disabling Symbolic-links is recommended to prevent assorted security risks
Links=0 # * Important:additional settings that can override those from this file!
# The files must end with '. Cnf ', and otherwise they ' ll be ignored.

 #!includedir/etc/mysql/conf.d/

This is basically the two lines, just add to the original configuration.

Log-bin = Mysql-bin
Server-id = 1

MY-S.CNF content is as follows

# Copyright (c) 2014, Oracle and/or its affiliates.
All rights reserved. # this are free software; Can redistribute it and/or modify # it under the terms of the GNU general public License as published Ftware Foundation;
Version 2 of the License. # This is distributed to the hope that it'll be useful, # but without any WARRANTY; Without even the implied warranty of # merchantability or FITNESS for A particular purpose.
The # GNU general public License for more details. # Your should have received a copy of the GNU general public, License # along with this program; If not, write to the free Software # Foundation, INC, Wuyi Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # The MyS
QL Community Server configuration file.   # for explanations # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [client] port = 3306 socket =/var/run/mysqld/mysqld.sock [Mysqld_safe] pid-file =/var/run/mysqld/mysqld.pid socket =/vaR/run/mysqld/mysqld.sock nice = 0 [mysqld] user = MySQL Pid-file =/var/run/mysqld/mysqld.pid socket =/var/run/ Mysqld/mysqld.sock Port = 3306 basedir =/usr DataDir =/var/lib/mysql tmpdir =/tmp Lc-messages-dir =/usr/share /mysql Explicit_defaults_for_timestamp log-bin = Mysql-bin Server-id = 2 # Instead of skip-networking The default is no
W to listen only on # localhost which are more compatible and are not less secure. #bind-address = 127.0.0.1 #log-error =/var/log/mysql/error.log # recommended in standard MySQL setup Sql_mode=no_engin E_substitution,strict_trans_tables # Disabling Symbolic-links is recommended to prevent assorted security risks
Links=0 # * Important:additional settings that can override those from this file!
# The files must end with '. Cnf ', and otherwise they ' ll be ignored.

 #!includedir/etc/mysql/conf.d/

Again, the main thing is that these two lines

Log-bin = Mysql-bin
Server-id = 2

2, OK, with the configuration file, you can start MySQL, first start the main library

$ docker run-d-e mysql_root_password=admin--name mysql-master-v/soft/my-m.cnf:/etc/mysql/my.cnf-p 3307:3306 MYSQL

3, start from the library

$ docker run-d-e mysql_root_password=admin--name mysql-slave-v/soft/my-s.cnf:/etc/mysql/my.cnf-p 3308:3306 MYSQL

4, connect the main library, and run the following command to create a user to synchronize data

$ GRANT REPLICATION SLAVE on *.* to ' backup ' @ '% ' identified by ' 123456 ';

5, view the main library status

$ show Master status;

Remember the value of file, position, if you do not find the data, please check the first, second step, configuration issues.
I found out about mysql-bin.000004, 312.

6, connect to from the library, run the following command, set the main library link

$ change Master to master_host= ' 121.32.32.54 ', master_user= ' backup ', master_password= ' 123456 ',
Master_log_file= ' mysql-bin.000004 ', master_log_pos=312,master_port=3307;

7. Start Sync

$ start slave;

8. View sync Status

$ Show Slave status

If you see waiting for master Send event ... Or whatever it is, you are now in the main library, the changes will be synchronized to the library from the

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.