Configure MySQL master and slave under Docker

Source: Internet
Author: User

Configure MySQL master-slave under native Docker

Install the Docker MySQL container first

$ docker pull MySQL:5.6

Pull two identical versions of MySQL

Start MySQL separately and set the root user password to admin:

// Master MySQL 3307:3306-d-e mysql_root_password=admin--name mysql-slave-v  3308:  3306 mysql:5.6

MySQL master configuration file my-m.cnf:

# Copyright (c) the, Oracle and/or its affiliates. All Rights reserved.## FreeSoftware; You can redistribute it and/or modify# it under the terms of the GNU general public, License as published by# the Free software Foundation; version 2Of the license.## This program is distributedinchThe hope that it'll be useful,# but without any WARRANTY; without even the implied WARRANTY of# merchantability or  FITNESS for A particular PURPOSE. See the# GNU general public License for  Moredetails.## You should has received a copy of the GNU general public license# along with this program;ifNotWriteto the Free software# Foundation, Inc.,WuyiFranklin St, Fifth Floor, Boston, MA02110-1301usa## the MySQL Community Server configurationfile. # # for Explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[Client]port=3306Socket=/var/run/mysqld/Mysqld.sock[mysqld_safe]pid-file=/var/run/mysqld/Mysqld.pidsocket=/var/run/mysqld/Mysqld.sock Nice=0[Mysqld]user=Mysqlpid-file=/var/run/mysqld/Mysqld.pidsocket=/var/run/mysqld/Mysqld.sockport=3306Basedir= /Usrdatadir=/var/lib/Mysqltmpdir= /tmpsecure-file-priv =NULLLC-messages-dir=/usr/share/Mysqlexplicit_defaults_for_timestamplog-bin = mysql-Bin Server-ID= -# Instead of Skip-Networking The default is now- listen only on# localhostwhichIs MoreCompatible and is not Lesssecure. #bind-address =127.0.0.1#log-error =/var/log/mysql/error.log# RecommendedinchStandard MySQL Setupsql_mode=no_engine_substitution,strict_trans_tables# Disabling Symbolic-links are recommended to prevent assorted security risks#symbolic-links=0# * Important:additional settings that can override those from thisfile!# The files must end with'. CNF', otherwise they'll be ignored.#!includedir/etc/mysql/conf.d/

MySQL master configuration file my-s.cnf:

# Copyright (c) the, Oracle and/or its affiliates. All Rights reserved.## FreeSoftware; You can redistribute it and/or modify# it under the terms of the GNU general public, License as published by# the Free software Foundation; version 2Of the license.## This program is distributedinchThe hope that it'll be useful,# but without any WARRANTY; without even the implied WARRANTY of# merchantability or  FITNESS for A particular PURPOSE. See the# GNU general public License for  Moredetails.## You should has received a copy of the GNU general public license# along with this program;ifNotWriteto the Free software# Foundation, Inc.,WuyiFranklin St, Fifth Floor, Boston, MA02110-1301usa## the MySQL Community Server configurationfile. # # for Explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[Client]port=3306Socket=/var/run/mysqld/Mysqld.sock[mysqld_safe]pid-file=/var/run/mysqld/Mysqld.pidsocket=/var/run/mysqld/Mysqld.sock Nice=0[Mysqld]user=Mysqlpid-file=/var/run/mysqld/Mysqld.pidsocket=/var/run/mysqld/Mysqld.sockport=3306Basedir= /Usrdatadir=/var/lib/Mysqltmpdir= /tmpsecure-file-priv =NULLLC-messages-dir=/usr/share/Mysqlexplicit_defaults_for_timestamplog-bin = mysql-Bin Server-ID=101# Instead of Skip-Networking The default is now- listen only on# localhostwhichIs MoreCompatible and is not Lesssecure. #bind-address =127.0.0.1#log-error =/var/log/mysql/error.log# RecommendedinchStandard MySQL Setupsql_mode=no_engine_substitution,strict_trans_tables# Disabling Symbolic-links are recommended to prevent assorted security riskssymbolic-links=0# * Important:additional settings that can override those from thisfile!# The files must end with'. CNF', otherwise they'll be ignored.#!includedir/etc/mysql/conf.d/

Note: The master profile differs from the Server-id of the configuration file.

Go to main MySQL:
" Clear && Docker exec-it mysql-master sh "

Link MySQL
Mysql-uroot-padmin

Create from user
CREATE USER ' slave ' @ '% ' identified by ' 12345678 '; GRANT REPLICATION SLAVE, REPLICATION CLIENT on *. * to ' SLAVE ' @ '% ';
Show master status;

Mysql>
Mysql> Show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 2386 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in Set (0.00 sec)

Record file and position.

Link from database
Bash-c "Clear && Docker exec-it mysql-slave sh"

Enter from the database
Mysql-uroot-p

Create
Change Master to master_host= ' 172.17.0.5 ', master_user= ' slave ', master_password= ' 12345678 ', master_port=3306, Master_ Log_file= ' mysql-bin.000003 ', master_log_pos=2386, master_connect_retry=30;

View master-slave MySQL IP in ps:docker

? Lib Docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5b0b0e6e33c MySQL "Docker-entrypoint ..." Hours ago up 2 minutes 33060/tcp, 0.0.0.0:3308->3306/tcp Mysql-slave
402ea137d6da MySQL "Docker-entrypoint ..." Hours ago up 3 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp Mysql-master
d905b168284e php:7.1.0-fpm "Docker-php-entryp ..." 2 days ago up 4 hours 0.0.0.0:9000->9000/tcp myphp
ae37295e5360 nginx "nginx-g ' daemon ..." 2 days ago up 4 hours 0.0.0.0:8080->80/tcp Mynginx
4725b5cd7515 redis:latest "Docker-entrypoint ..." 3 months ago up 5 hours 0.0.0.0:6380->6379/tcp Myredis
? Lib
? Lib Docker inspect--format ' {{. Networksettings.ipaddress}} ' 402
172.17.0.5


Start synchronization
Start slave;

View status

Mysql> show Slave status\g;
1. Row ***************************
Slave_io_state:waiting for Master to send event
master_host:172.17.0.5
Master_user:slave
master_port:3306
Connect_retry:30
master_log_file:mysql-bin.000003
Read_master_log_pos:2386
relay_log_file:e5b0b0e6e33c-relay-bin.000002
relay_log_pos:2014
relay_master_log_file:mysql-bin.000003
Slave_io_running:yes
Slave_sql_running:yes
replicate_do_db:
replicate_ignore_db:
Replicate_do_table:
Replicate_ignore_table:
Replicate_wild_do_table:
Replicate_wild_ignore_table:
last_errno:0
Last_error:
skip_counter:0
Exec_master_log_pos:2386
relay_log_space:2229
Until_condition:none
Until_log_file:
until_log_pos:0
Master_ssl_allowed:no
Master_ssl_ca_file:
Master_ssl_ca_path:
Master_ssl_cert:
Master_ssl_cipher:
Master_ssl_key:
seconds_behind_master:0
Master_ssl_verify_server_cert:no
last_io_errno:0
Last_io_error:
last_sql_errno:0
Last_sql_error:
Replicate_ignore_server_ids:
master_server_id:100
master_uuid:7ce8f23c-a79f-11e8-a391-0242ac110005
Master_Info_File:mysql.slave_master_info
sql_delay:0
Sql_remaining_delay:null
Slave_sql_running_state:slave have read all relay log; Waiting for more updates
master_retry_count:86400
Master_bind:
Last_io_error_timestamp:
Last_sql_error_timestamp:
MASTER_SSL_CRL:
Master_ssl_crlpath:
Retrieved_gtid_set:
Executed_gtid_set:
auto_position:0
replicate_rewrite_db:
Channel_name:
Master_tls_version:
Master_public_key_path:
get_master_public_key:0
1 row in Set (0.00 sec)

ERROR:
No query specified



Are all successful for Yes
Slave_io_running:yes
Slave_sql_running:yes

Configure MySQL master and slave under Docker

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.