当前位置:网站首页>Docker builds MySQL master-slave

Docker builds MySQL master-slave

2022-06-23 02:43:00 buiu

mysql Master-slave
#  Lord mysql start-up 
docker run --privileged=true -d -p 3307:3306  --name='mysql_master' \
-e MYSQL_ROOT_PASSWORD=123456 \
-v /opt/mysql_master/log:/var/log/mysql \
-v /opt/mysql_master/data:/var/lib/mysql \
-v /opt/mysql_master/conf:/etc/mysql/conf.d mysql
#  from mysql start-up 
docker run --privileged=true -d -p 3308:3306 \
-e MYSQL_ROOT_PASSWORD=123456 --name='mysql_slave' \
-v /opt/mysql_slave/log:/var/log/mysql \
-v /opt/mysql_slave/data:/var/lib/mysql \
-v /opt/mysql_slave/conf:/etc/mysql/conf.d mysql

#  Lord mysql To configure 
	#  Lord mysql The configuration file 
		vim /opt/mysql_master/conf/my.cnf
	#  Restart master mysql
		docker restart mysql_master
		
	docker exec -it mysql_master /bin/bash 
  #  Create a user for data synchronization 
  mysql -uroot -p123456
  create user 'slave'@'%' identified by '123456';
  grant replication slave,replication client on *.* to 'slave'@'%'; 	#  Access configuration 
  #  Confirm master mysql Master slave status of 
  show master status;
  
#  from mysql To configure 
	#  from mysql The configuration file 
	vim /opt/mysql_slave/conf/my.cnf
	#  Restart from mysql
	docker restart mysql_slave
	docker exec -it mysql_slave /bin/bash 
	mysql -uroot -p123456
	#  Configure master-slave replication 
	change master to master_host='10.122.1.86', master_user='slave', master_password='123456', master_port=3307, master_log_file='mall-mysql-bin.000001', master_log_pos=784, master_connect_retry=30;
	#  Parameters, : master_log_file and master_log_pos In the main mysql Use in show master status; master_connect_retry Connection failure retry interval ; master_log_pos Specify where the database starts copying data 
	#  Enable master-slave replication 
	start slave;
	#  confirm 
	show slave status \G;
	

<details>

<summary> Lord mysql The configuration file </summary>

<pre><code>

mysqld

It should be unique in the same LAN

server-id=101

Specify the name of the database that does not need to be synchronized

binlog-ignore-db=mysql

Turn on binary log

log-bin=mall-mysql-bin

Set the memory size of binary log ( Business )

binlog_cache_size=1M

Set the binary log format to use (mixed, statement, row)

binlog_format=mixed

Binary log expiration cleanup time , The default value is 0, Does not automatically clean up

expire_logs_days=7

Skip the types of some errors encountered during master-slave replication

slave_skip_errors=1062

</code></pre>

</details>

<details>

<summary> from mysql The configuration file </summary>

<pre><code>

mysqld

It should be unique in the same LAN

server-id=102

Specify the name of the database that does not need to be synchronized

binlog-ignore-db=mysql

Turn on binary log function , in preparation for slave As an instance of other databases master When using

log-bin=mall-mysql-slave1-bin

Set the memory size of binary log ( Business )

binlog_cache_size=1M

Set the binary log format to use (mixed, statement, row)

binlog_format=mixed

Binary log expiration cleanup time , The default value is 0, Does not automatically clean up

expire_logs_days=7

Skip the types of some errors encountered during master-slave replication

slave_skip_errors=1062

relay_log Configure relay logs

relay_log=mall-mysql-relay-bin

log_slave_updates Express slave Write the copy event to your own binary log

log_slave_updates=1

slave Set to read only

read_only=1

</code></pre>

</details>

原网站

版权声明
本文为[buiu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201302058373789.html