前言

将阿里云数据库物理备份的数据下载到本地,使用Docker来加载,来做数据升级和迁移的本地测试。

HOW TO

  1. 将线上数据库物理备份,并下载到本地

如下载后放置在~/Downloads/hins4577021_data_20181203163125.tar

  1. 将数据库备份文件解压, 如:
1
2
3
mkdir -p ~/Downloads/data
cd ~/Downloads
tar -xvf hins4577021_data_20181203163125.tar -C ./data
  1. 使用mysql 5.7 docker镜像,加载数据备份数据
1
2
3
4
5
6
docker run --name some-mysql -v "$PWD/data":/var/lib/mysql -e MYSQL_ROOT_PASSWORD=go -p 3306:3306 -d mysql:5.7

# 查看运行的容器
docker ps                                                                                            0 [10:51:06]
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
0a128332fe96        mysql:5.7           "docker-entrypoint.s…"   10 minutes ago      Up 10 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp   some-mysql
  1. 连接数据库(使用线上数据库的用户名和密码)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
mysql -h 127.0.0.1 -P3306 -u saas -p                                                                 0 [10:50:02]
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>