Docker: MySQL主从

master.cnf文件:


[mysqld]

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

datadir = /var/lib/mysql

symbolic-links=0

character-set-server = utf8

#skip-networking

innodb_print_all_deadlocks = 1

max_connections = 2000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 28M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log-bin = mysql-bin

server-id = 1

binlog_format = mixed

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

interactive_timeout = 28800

wait_timeout = 28800

# Recommended in standard MySQL setup

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

 

 

slave.cnf文件:

[mysqld]

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

datadir = /var/lib/mysql

symbolic-links=0

character-set-server = utf8

#skip-networking

innodb_print_all_deadlocks = 1

max_connections = 2000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 28M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log-bin = mysql-bin

server-id = 2

binlog_format = mixed

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

interactive_timeout = 28800

wait_timeout = 28800

# Recommended in standard MySQL setup

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M


docker run -p 3306:3306 --name master -v /root/master.cnf:/etc/mysql/conf.d/master.cnf -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker run -p 3307:3306 --name slave -v /root/slave.cnf:/etc/mysql/conf.d/slave.cnf -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker run -p 3308:3306 --name slave2 -v /root/slave.cnf:/etc/mysql/conf.d/slave.cnf -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7


docker exec -it master /bin/bash
docker exec -it slave /bin/bash
docker exec -it slave2 /bin/bash

mysql -uroot -p123456

create user 'amadeus' identified by '123456';
GRANT ALL PRIVILEGES ON *.* TO 'amadeus'@'%' IDENTIFIED BY '123456'; 
FLUSH PRIVILEGES;

show master status;







change master to master_host='192.168.183.235', master_port=3306,master_user='amadeus',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=0;
start slave;
show slave status\G;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值