0%

dbdeployer工具

dbdeployer能够快速部署数据库测试环境,一键实现Oracle MySQL、Percona MySQL、MariaDB、TiDB、MySQL NDB Cluster、PXC等测试环境的构建。

项目地址:dbdeployer

安装dbdeployer

1
2
3
4
5
6
[root@t-luhx02-v-szzb mysql]# tar -xvf dbdeployer-1.47.0.linux.tar.gz 
dbdeployer-1.47.0.linux
[root@t-luhx02-v-szzb mysql]# mv dbdeployer-1.47.0.linux /usr/local/bin/dbdeployer
[root@t-luhx02-v-szzb mysql]# chmod +x /usr/local/bin/dbdeployer
[root@t-luhx02-v-szzb mysql]# dbdeployer --version
dbdeployer version 1.47.0

配置dbdeployer

默认配置文件为当前用户的$HOME/.dbdeployer/config.json作为配置文件,可以通过dbdeplyoer defaults export导出并修改配置或者直接通过dbdeployer defaults update来更新默认文件,配置文件包含MySQL初始信息。

1
2
[root@t-luhx02-v-szzb mysql]# dbdeployer defaults update sandbox-binary /media/mysql
[root@t-luhx02-v-szzb mysql]# dbdeployer defaults update sandbox-home /usr/local/bin/

MySQL版本管理

dbdeployer在联网环境下,支持在线下载多种版本的MySQL介质

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[root@t-luhx02-v-szzb mysql]# dbdeployer downloads list
Available tarballs ()
name OS version flavor size minimal
-------------------------------------------------------- ------- --------- ------------- -------- ---------
tidb-master-linux-amd64.tar.gz Linux 3.0.0 tidb 26 MB
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz Linux 8.0.16 mysql 461 MB
mysql-8.0.16-linux-x86_64-minimal.tar.xz Linux 8.0.16 mysql 44 MB Y
mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz Linux 5.7.27 mysql 645 MB
mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz Linux 8.0.17 mysql 480 MB
mysql-8.0.17-linux-x86_64-minimal.tar.xz Linux 8.0.17 mysql 45 MB Y
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz Linux 5.7.26 mysql 645 MB
mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz Linux 5.6.44 mysql 329 MB
mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz Linux 5.5.62 mysql 199 MB
mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz Linux 8.0.15 mysql 376 MB
mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz Linux 8.0.13 mysql 394 MB
mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz Linux 5.7.25 mysql 645 MB
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz Linux 5.6.43 mysql 329 MB
mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz Linux 5.5.61 mysql 199 MB
mysql-5.1.73-linux-x86_64-glibc23.tar.gz Linux 5.1.73 mysql 134 MB
mysql-5.0.96.tar.xz Linux 5.0.96 mysql 5.5 MB Y
mysql-5.1.72.tar.xz Linux 5.1.72 mysql 10 MB Y
mysql-5.5.61.tar.xz Linux 5.5.61 mysql 6.6 MB Y
mysql-5.5.62.tar.xz Linux 5.5.62 mysql 6.6 MB Y
mysql-5.6.43.tar.xz Linux 5.6.43 mysql 9.0 MB Y
mysql-5.6.44.tar.xz Linux 5.6.44 mysql 9.1 MB Y
mysql-5.7.25.tar.xz Linux 5.7.25 mysql 23 MB Y
mysql-5.7.26.tar.xz Linux 5.7.26 mysql 23 MB Y
mysql-5.0.96-linux-x86_64-glibc23.tar.gz Linux 5.0.96 mysql 127 MB
mysql-4.1.22.tar.xz Linux 4.1.22 mysql 4.6 MB Y
mysql-cluster-gpl-7.6.10-linux-glibc2.12-x86_64.tar.gz Linux 7.6.10 ndb 916 MB
mysql-cluster-8.0.16-dmr-linux-glibc2.12-x86_64.tar.gz Linux 8.0.16 ndb 1.1 GB
mysql-cluster-gpl-7.6.11-linux-glibc2.12-x86_64.tar.gz Linux 7.6.11 ndb 916 MB
mysql-cluster-8.0.17-rc-linux-glibc2.12-x86_64.tar.gz Linux 8.0.17 ndb 1.1 GB
mysql-shell-8.0.17-linux-glibc2.12-x86-64bit.tar.gz Linux 8.0.17 mysql-shell 30 MB
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz Linux 5.7.28 mysql 725 MB
mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz Linux 8.0.18 mysql 504 MB
mysql-8.0.18-linux-x86_64-minimal.tar.xz Linux 8.0.18 mysql 48 MB Y
mysql-8.0.19-linux-x86_64-minimal.tar.xz Linux 8.0.19 mysql 45 MB
mysql-cluster-8.0.19-linux-glibc2.12-x86_64.tar.gz Linux 8.0.19 ndb 1.2 GB
mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz Linux 5.7.29 mysql 665 MB

在内网环境中,也可以选择自行下载MySQL介质,并上传到sandbox-binary参数指定的目录下进行解压,默认为$HOME/opt/mysql。

1
2
[root@t-luhx02-v-szzb mysql]# cd /media/mysql
[root@t-luhx02-v-szzb mysql]# dbdeployer unpack mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

测试实例

1
2
3
4
[root@t-luhx02-v-szzb mysql]# dbdeployer deploy single 5.6.46 --gtid --my-cnf-options="character_set_server=utf8mb4" --db-user=msandbox --db-password=Abcd123#
Database installed in /usr/local/bin/msb_5_6_46
run 'dbdeployer usage single' for basic instructions'
. sandbox server started

连接实例

1
[root@t-luhx02-v-szzb mysql]# mysql -uroot -p -h 127.0.0.1 -P5646

也可以进入实例数据目录通过use连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@t-luhx02-v-szzb msb_5_6_46]# ./use -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.46-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 [localhost:5646] {msandbox} ((none)) >

查看已安装的环境

1
2
3
4
5
[root@t-luhx02-v-szzb mysql]# dbdeployer sandboxes --full-info
.------------.--------.---------.-----------.---------.--------.-------.--------.
| name | type | version | host | port | flavor | nodes | locked |
+------------+--------+---------+-----------+---------+--------+-------+--------+
| msb_5_6_46 | single | 5.6.46 | 127.0.0.1 | [5646 ] | mysql | 0 |

查看运行状态

1
2
3
[root@t-luhx02-v-szzb mysql]# dbdeployer global status
# Running "status" on msb_5_6_46
msb_5_6_46 on

重启实例

1
2
3
4
5
6
[root@t-luhx02-v-szzb ~]# dbdeployer global stop msb_5_6_46
# Running "stop" on msb_5_6_46
stop /usr/local/bin/msb_5_6_46

[root@t-luhx02-v-szzb ~]# dbdeployer global start msb_5_6_46
# Running "start" on msb_5_6_46

删除实例

1
2
3
4
5
6
[root@t-luhx02-v-szzb ~]# dbdeployer delete msb_5_6_46
List of deployed sandboxes:
/usr/local/bin/msb_5_6_46
Running /usr/local/bin/msb_5_6_46/stop
Running rm -rf /usr/local/bin/msb_5_6_46
Directory /usr/local/bin/msb_5_6_46 deleted

对实例加锁,防止误删

1
dbdeployer admin lock msb_5_6_46

dbdeployer还有其它许多功能,更多内容请通过项目地址对其进行了解。