您的位置:首页 > 文旅 > 美景 > 东营企业自助建站_广东官网网站建设平台_上海百度公司地址在哪里_外汇seo公司

东营企业自助建站_广东官网网站建设平台_上海百度公司地址在哪里_外汇seo公司

2025/1/5 8:41:53 来源:https://blog.csdn.net/m0_70982551/article/details/144792171  浏览:    关键词:东营企业自助建站_广东官网网站建设平台_上海百度公司地址在哪里_外汇seo公司
东营企业自助建站_广东官网网站建设平台_上海百度公司地址在哪里_外汇seo公司

docker-compos mysql5.7主从配置

docker-compose目录结构

配置文件

master/my.cnf

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
secure-file-priv=/var/lib/mysql-files
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamplog-bin = mysql-bin
server-id = 1

slave/my.cn

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
secure-file-priv=/var/lib/mysql-files
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamplog-bin = mysql-bin
server-id = 2

docker-compose.yml文件

version: '3.2'
services:mysql-master:image: "mysql:5.7"container_name: mysql-masterrestart: alwaysprivileged: trueenvironment:MYSQL_ROOT_PASSWORD: 123456  #主库root用户的密码command:--default-authentication-plugin=mysql_native_password--character-set-server=utf8mb4--collation-server=utf8mb4_general_ci--explicit_defaults_for_timestamp=true--lower_case_table_names=1--max_allowed_packet=128M;ports:- 3306:3306  #映射宿主机端口:容器端口volumes:  #宿主机配置目录或文件挂载到容器- ./master/my.cnf:/etc/mysql/my.cnf- ./master/mysql-files:/var/lib/mysql-files- ./master/data:/var/lib/mysql- ./master/log:/var/log/networks:mysql-network:ipv4_address: 10.2.0.2mysql-slave:image: "mysql:5.7"container_name: mysql-slaverestart: alwaysprivileged: trueenvironment:MYSQL_ROOT_PASSWORD: 123456  #从库root用户的密码command:--default-authentication-plugin=mysql_native_password--character-set-server=utf8mb4--collation-server=utf8mb4_general_ci--explicit_defaults_for_timestamp=true--lower_case_table_names=1--max_allowed_packet=128M;ports:- 3307:3306  #映射宿主机端口:容器端口volumes:  #宿主机配置目录或文件挂载到容器- ./slave/my.cnf:/etc/mysql/my.cnf- ./slave/mysql-files:/var/lib/mysql-files- ./slave/data:/var/lib/mysql- ./slave/log:/var/log/networks:mysql-network:ipv4_address: 10.2.0.3
networks:  #定义容器连接网络mysql-network:driver: bridgeipam:driver: defaultconfig:- subnet: 10.2.0.0/24

运行

在配置文件目录下使用docker compose up -d运行

主节点的mysql配置:

进入主节点docker容器

docker exec -it mysql-master bash
mysql -uroot -p123456

#创建账号用于从机连接主机

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '123456';

权限立刻生效

flush privileges;

查看binglog信息

show master status \G;

从节点的mysql配置:

进入从节点

docker exec -it mysql-slave bash
mysql -uroot -p123456

配置连接

下面几个参数需要与主节点的信息对应

CHANGE MASTER TO MASTER_HOST='10.2.0.2', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=589;

启动服务

start slave;

查看状态

show slave status \G;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com