Linux系统必须安装有Go语言: 下载最新的包:https://github.com/datacharmer/dbdeployer/releases 解压: tar -xzf dbdeployer-1.5.0.linux.tar.gz 赋予执行权限: chmod +x dbdeployer-1.5.0.linux 拷贝到bin目录: sudo mv dbdeployer-1.5.0.linux /usr/local/bin/dbdeployer dbdeployer可以快速搭建多个MySQL测试环境(主从复制,主主复制,GTID复制,组复制(单主或多主),多源复制等) 部署MySQL环境都是秒级别(10-30秒,根据实例多少有关),使用起来很方便,还有各种管理命令。 dbdeployer unpack mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz --sandbox-binary=/usr/local dbdeployer deploy single 8.0.11 --bind-address=0.0.0.0 --port=3308 --sandbox-home=/home/data --sandbox-binary=/usr/local --sandbox-home 数据文件的安装目录 --sandbox-binary 是安装MySQL的二进制文件程序目录 --bind-address 4个0代表全部 --port 代表MySQL的端口 -- cd 到/home/data下 --mysql 8.0.11 创建用户 ./use 进去 修改密码和权限,否则不能修改Authentication plugin 'caching_sha2_password' cannot be loaded: ALTER user'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'cc.123'; create USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'cc.123'; FLUSH PRIVILEGES; --再授权 mysql -u root -p -S /tmp/mysql_sandbox3308.sock -- 进入 grant all on *.* to 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; 如果想在安装的时候就赋予权限,直接使用参数: --post-grants-sql="grant all on *.* to 'root'@'%' WITH GRANT OPTION " --删除已经部署的mysql
dbdeployer delete rsandbox_8_0_11 --sandbox-home=/home/data -- sandbox-binary=/usr/local;
--这里的:rsandbox_8_0_11 是文件夹名称
--部署1主多从(1拖4) (using ports 18601, 18602, 18603,18604)
dbdeployer deploy replication 8.0.11 --bind-address=0.0.0.0 --base-port=18600 --sandbox-home=/home/data --sandbox-binary=/usr/local --nodes=4;
--部署4个mysql,(using ports 18601, 18602, 18603,18604)
dbdeployer deploy multiple 8.0.11 --bind-address=0.0.0.0 --base-port=18600 --sandbox-home=/home/data --sandbox-binary=/usr/local --nodes=4;安装3主2从(多主多从):
dbdeployer deploy replication --topology=fan-in --nodes=5 --master-list="1,2,3" --bind-address=0.0.0.0 --native-auth-plugin
--slave-list="4,5" 8.0.11 --sandbox-home=/home/data --remote-access="%" --sandbox-binary=/usr/local --db-password="cc.123" --db-user="sa" --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION "
--remote-access="%" 账户远程访问的IP,% 为全部
--db-user 新数据库账户
--db-password 数据库密码
--post-grants-sql 后面执行的数据库授权Sql
--native-auth-plugin
客户端如SQLLog可以访问MySQL,是在MySQL 8.0.4+ 有效
安装组复制:
dbdeployer deploy replication --topology=group --bind-address=0.0.0.0 8.0.11 --sandbox-home=/home/data --remote-access="%" --sandbox-binary=/usr/local --native-auth-plugin
--db-password="cc.123" --db-user="sa" --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION ";
加上:--single-primary
明确是单主
dbdeployer deploy --topology=all-masters replication --bind-address=0.0.0.0 8.0.11 --sandbox-home=/home/td --remote-access="%" --sandbox-binary=/usr/local --native-auth-plugin
--db-password="cc.123" --db-user="sa" --post-grants-sql="grant all on *.* to 'sa'@'%' WITH GRANT OPTION " --concurrent;
说明:
$ dbdeployer deploy replication 5.7.21 # (implies topology = master-slave) 默认主从 $ dbdeployer deploy --topology=master-slave replication 5.7.21 # (explicitly setting topology) 明确主从 $ dbdeployer deploy --topology=group replication 5.7.21 组复制多主 $ dbdeployer deploy --topology=group replication 8.0.4 --single-primary 组复制单主 $ dbdeployer deploy --topology=all-masters replication 5.7.21 多主复制 $ dbdeployer deploy --topology=fan-in replication 5.7.21 多主单(多)从复制
注意: 安装的过程中当前目录一定有,不然报错。比如在删除的rsandbox_8_0_11文件夹下执行dbdeployer命令
配置后的备份:cd到MySQL的bin下执行
./mysqldump -h 192.168.60.167 -u sa -p -P8011 --socket=/tmp/mysql_sandbox8011.sock test > test_db.sql;