docker+mysql+ Read/write separation

Source: Internet
Author: User

One, pull the MySQL image file
Docker pull MySQL
Second, view the image
Docker images
Iii. Creating a configuration file directory
Mkdir/data/docker/mysql/{master,slave}-PV

Iv. master/slave configuration files
Master:/data/docker/mysql/master/my.cnf
[Mysqld]
server-id=1
Log-bin=master-bin
Log-bin-index=master-bin.index
Default-authentication-plugin=mysql_native_password
from:/data/docker/mysql/slave/my.cnf
[Mysqld]
server-id=2
skip-slave-start=true
Read_only=on
Relay-log=relay-bin
Relay-log-index=relay-bin.index
Default-authentication-plugin=mysql_native_password

v. Launching a master/slave database Docker instance
Create the main library data file directory
Mkdir/data/docker/mysql/master/data
start the main library instance
Docker run-d-e mysql_root_password=123456--name mysql-master-v/data/docker/mysql/master/data:/var/lib/mysql-v /data/docker/mysql/master/my.cnf:/etc/my.cnf-p 3306:3306 MySQL
after the creation of the container to change the password: otherwise it will error, it is said that the new features of MySQL:
The error is as follows:
ERROR 2059 (HY000): Authentication plugin ' Caching_sha2_password ' cannot be loaded:/usr/lib64/mysql/plugin/caching _sha2_password.so:cannot open Shared object file:no such file or directory
Enter the container
Docker exec-it Mysql-master/bin/bash
log in to MySQL
mysql-uroot-p123456-h127.0.0.1
Change Password
ALTER USER ' root ' @ '% ' identified with Mysql_native_password by ' Fansik ';


Create a directory from the library data file
Mkdir/data/docker/mysql/slave/data
starting from a library instance
Docker run-d-e mysql_root_password=123456--name mysql-slave-v/data/docker/mysql/slave/data:/var/lib/mysql-v/ Data/docker/mysql/slave/my.cnf:/etc/my.cnf-p 3307:3306 MySQL
after the creation of the container to change the password: otherwise it will error, it is said that the new features of MySQL:
The error is as follows:
ERROR 2059 (HY000): Authentication plugin ' Caching_sha2_password ' cannot be loaded:/usr/lib64/mysql/plugin/caching _sha2_password.so:cannot open Shared object file:no such file or directory
Enter the container
Docker exec-it Mysql-slave/bin/bash
log in from MySQL
mysql-uroot-p123456-h127.0.0.1-p3307
Change Password
ALTER USER ' root ' @ '% ' identified with Mysql_native_password by ' Fansik ';

Vi. Configuring master/Slave replication
View the IP address of two containers
Main Library:
[email protected] data]# Docker inspect |grep ' IPAddress '
"secondaryipaddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",

From library:
[email protected] data]# Docker inspect |grep ' IPAddress '
"secondaryipaddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",

1. Login to the main library to add copy account
MySQL [(None)]> CREATE USER ' slave ' @ '% ' identified by ' slave ';
Query OK, 0 rows affected (0.09 sec)

MySQL [(None)]> GRANT REPLICATION SLAVE on * * to ' SLAVE ' @ '% ';
Query OK, 0 rows affected (0.01 sec)

MySQL [(None)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

2. View the status of the main library
MySQL [(none)]> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000004 | 1363 |                  |                   | |
+-------------------+----------+--------------+------------------+-------------------+

3. Configure copy information from library
Change Master to master_host= ' 172.17.0.2 ', master_user= ' slave ', master_password= ' slave ', master_log_file= ' Master-bin.000004 ', master_log_pos=1363,master_port=3306;

Read and write separation configuration, using middleware as Amoeba
Reference Document:http://www.cnblogs.com/fansik/p/7168501.html

docker+mysql+ Read/write separation

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.