LoginSignup
3
4

More than 5 years have passed since last update.

Docker Mysql Replication

Posted at

Installation

Host
host#prompt> docker pull ubuntu:14.04

DB Master

host#prompt> docker run -it --name dbmaster -h dbmaster ubuntu:14.04 bash
dbmaster#prompt> apt-get update
dbmaster#prompt> apt-get -y install  mysql-client mysql-server vim

DB Slave

host#prompt>docker run -it --name dbslave -h dbslave --link dbmaster:dbmaster -p 8080:80 ubuntu:14.04 bash
dbslave#prompt> apt-get update
dbslave#prompt> apt-get -y install  mysql-client mysql-server vim
dbslave#prompt> apt-get -y install php5 libapache2-mod-php5 php5-mcrypt apache2  php5-mysql

with docker inspect ContainerName you can see the information of the container between other things the IP, on my case:

Host

docker inspect dbmaster  = 172.17.0.2
docker inspect dbslave    = 172.17.0.3

Configuration

Master
Edit /etc/mysql/my.cnf se realizan las configuracion de mysql, test es el nombre de la base de datos

1.png

dbmaster#prompt> service mysql start
dbmaster#prompt> mysql -u root -p123
mysql > GRANT REPLICATION SLAVE ON *.* TO 'suser'@'%' IDENTIFIED BY 'pass';
mysql > GRANT ALL PRIVILEGES ON test.* TO ‘suser’@’%’ IDENTIFIED BY 'pass';
mysql > FLUSH PRIVILEGES;

2.png

Slave
Edit /etc/mysql/my.cnf

3.png

dbslave#prompt> service mysql restart
dbslave#prompt> mysql -u root -p123
mysql >  CHANGE MASTER TO MASTER_HOST='172.17.0.2', MASTER_USER='suser',  MASTER_PASSWORD='pass',  MASTER_LOG_FILE='mysql-bin.000006',  MASTER_LOG_POS=  107;
mysql > START SLAVE;
mysql > SHOW SLAVE STATUS\G

4.png

5.png

Apache

If you want a query on dbslave to dbmaster we can use PHP, the Mine is "consulta.php" on /var/www/html/ and start the service

dbslave#prompt> service apache2 start

6.png

Resource

http://terraltech.com/mysql-replication-setup-on-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4