惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 王伟晔

利用asp.net Core开发webapi对接云之家智能审批数据互联控件 Windows 2012安装odoo12 Windows有点腻了?不如试试Ubuntu. 处理范例代码Webapi中的Mongodb的Bson中ObjectId反序列化异常 用app.net Core搞掂多国语言网站 重建程序员能力(3)-asp.net MVC框架增加Controller 重建程序员能力(2)-如何使asp.net mvc应用增加js和其他功能 重建程序员能力(1) asp.net mvc 5发布部署遇到403.14 我需要在Web上完成一个图片上传的功能(+2) 我需要在Web上完成一个图片上传的功能后续(+1) 我需要在Web上完成一个图片上传的功能 android-studio-bundle-141.1980579-windows download Site Razor提高WebPage代码的易读性 C# Hello World - 王伟晔 用params关键字增强代码的可读性 陌生的yield关键字 发现Visual Studio隐含的大礼包--漂亮的Visual Studio图像库 职业程序员必须要有的工作态度(之一)
docker 主从mysql配置
王伟晔 · 2024-08-03 · via 博客园 - 王伟晔

1、主机容器
docker run -d --name mysql-master --network my_network -p 3307:3306 -e MYSQL_ROOT_PASSWORD=密码 mysql

2、从机容器
docker run -d --name mysql-slave --network my_network -p 3308:3306 -e MYSQL_ROOT_PASSWORD=密码 mysql

3、在主机修改mysql配置
[mysqld]
log-bin = mysql-bin
server-id = 1 #主机是1

重启容器

4、在主机数据库中运行

CREATE USER'replication_user'@'%' IDENTIFIED BY '密码';
GRANT REPLICATION SLAVE ON *.* TO'replication_user'@'%';
ALTER USER'replication_user'@'%' IDENTIFIED WITH mysql_native_password BY'密码';


5、在从机修改mysql配置
[mysqld]
log-bin = mysql-bin
server-id = 2 #主机是2

重启容器

6、在从机数据库中运行

CHANGE MASTER TO MASTER_HOST='从机获得的IP地址',MASTER_PORT=3306, MASTER_USER='replication_user', MASTER_PASSWORD='密码', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=0;
START SLAVE;

还有一个问题,当前docker的mysql官方容器已经更新到9.0.1

1、主服务器配置更新

CREATE USER'replica_user'@'%' IDENTIFIED BY '密码';

GRANT REPLICATION SLAVE ON *.* TO'replica_user'@'%';

ALTER USER'replica_user'@'%' IDENTIFIED WITH caching_sha2_password BY '密码';

FLUSH PRIVILEGES;

2、从服务器设置

STOP REPLICA;

CHANGE REPLICATION SOURCE TO

  SOURCE_HOST='mysql-master',

  SOURCE_USER='replica_user',

  SOURCE_PASSWORD='密码',

SOURCE_SSL=1,

  SOURCE_LOG_FILE='mysql-bin.000001',

  SOURCE_LOG_POS=0;

START REPLICA;