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

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

补陋阁 RSS 2.0

补陋阁 补陋阁 补陋阁 补陋阁 补陋阁 补陋阁 补陋阁 补陋阁 补陋阁
补陋阁
补陋阁 · 2025-11-25 · via 补陋阁 RSS 2.0

起因

之前改博客都是直接在生产环节直接操作Mysql库,最近再重构和修改BUG,所以打算本地也搭建一个Mysql,但是不想用安装包的方式安装,就使用了docker安装在本地。电脑上使用的DataGrip来管理数据库的,他没办法像Navicat直接远端拷贝过来,所以想办法弄一个快速同步的方案。

过程

搭建本地mysql

services:
  mysql:
    image: mysql:8.0.41
    container_name: mysql8
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword123
      MYSQL_DATABASE: nuxt3_blog
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword

执行docker compose -f mysql_docker.yml up -d创建容器

# 远端数据库配置
REMOTE_HOST=10.0.0.8
REMOTE_PORT=3306
REMOTE_DB=prod_db
REMOTE_USER=admin
REMOTE_PASS='Abc123!'

# 本地 docker 容器 MySQL 配置
LOCAL_CONTAINER=mysql8
LOCAL_DB=mydatabase
LOCAL_USER=myuser
LOCAL_PASS='mypassword'

设置后,你只需执行:

docker exec -i "$LOCAL_CONTAINER" sh -c \
  "mysqldump -h $REMOTE_HOST -P$REMOTE_PORT -u $REMOTE_USER -p$REMOTE_PASS $REMOTE_DB" \
  | docker exec -i "$LOCAL_CONTAINER" mysql -u "$LOCAL_USER" -p"$LOCAL_PASS" "$LOCAL_DB"

即可自动完成远端 → 本地容器的导入。