作者:杨涛涛
资深数据库专家,专研 MySQL 十余年。擅长 MySQL、PostgreSQL、MongoDB 等开源数据库相关的备份恢复、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相关技术支持、MySQL 相关课程培训等工作。
本文来源:原创投稿
*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
首先说明如果完全按照官网文档来操作,肯定是没有问题的,DBLE 官网文档已经写的很详细了。
刚好我环境中有最新的 MySQL docker 镜像(MySQL 8.0.29),我偷懒把 DBLE 后台 MySQL 版本换成 8.0.29 ,子网换成172.20.0.0/16(我本机已有其他 docker 容器占用默认子网运行)。
root@ytt-large:/home/ytt# docker image ls | grep -E '^action|^mysql'
mysql 8.0.29 b2500a44757f 8 days ago 524MB
actiontech/dble latest 9988614a8e4b 6 months ago 755MB
root@ytt-large:/home/ytt# docker network create \
> -o "com.docker.network.bridge.name"="dble-net" \
> --subnet 172.20.0.0/16 dble-net
360a9408c35cd8b8d49ad2e58ca447d5518dbea2d954badc0e618ad5d0c072a1
root@ytt-large:/home/ytt# docker run --name backend-mysql1 \
> --ip 172.20.0.2 -e MYSQL_ROOT_PASSWORD=123456 \
> -p 33061:3306 --network=dble-net \
> -d mysql:8.0.29 --server-id=1
54505aeca71ae7c4553a0fa98e705ee302cdfc08c2b472768afc6170dddf6d37
root@ytt-large:/home/ytt# docker run --name backend-mysql2 \
> --ip 172.20.0.3 -e MYSQL_ROOT_PASSWORD=123456 \
> -p 33062:3306 --network=dble-net \
> -d mysql:8.0.29 --server-id=2
5f907b977fc242be35dc01840a5393f2ee754572dd1d59e2fb072032df1ed8d0
root@ytt-large:/home/ytt# docker run -d -i -t --name dble-server \
> --ip 172.20.0.5 -p 8066:8066 -p 9066:9066 \
> --network=dble-net actiontech/dble:latest
df80d0e2451c237afb4792f93e29738579f125288daf0dfee4484ddca8350110
root@ytt-large:/home/ytt# docker logs dble-server
dble init&start in docker
Starting dble-server...
wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
wait-for-it.sh: 127.0.0.1:8066 is available after 6 seconds
init shardingNode and execute template_table.sql
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
dble init finish
root@ytt-large:/home/ytt# docker exec -it dble-server /bin/bash
[root@df80d0e2451c /]# cat /opt/dble/conf/db.xml | grep 172
[root@df80d0e2451c /]# dble init&start in docker
Starting dble-server...
wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
wait-for-it.sh: 127.0.0.1:8066 is available after 2 seconds
init shardingNode and execute template_table.sql
ERROR 1044 (HY000) at line 200 in file: '/opt/dble/conf/template_table.sql': Access denied for user 'root' to database 'testdb2'
ERROR 1146 (42S02) at line 202 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test1' doesn't exist in the config of sharding
ERROR 1146 (42S02) at line 207 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test1' doesn't exist
ERROR 1146 (42S02) at line 210 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test2' doesn't exist in the config of sharding
ERROR 1146 (42S02) at line 215 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test2' doesn't exist
dble init finish
root@ytt-large:/home/ytt# mysql -uroot -p123456 -P8066 -h 127.0.0.1 -e "show grants for root" -s |grep 'CREATE'
mysql: [Warning] Using a password on the command line interface can be insecure.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE,... ON *.* TO `root`@`%` WITH GRANT OPTION
[root@df80d0e2451c ~]# cat /opt/dble/conf/user.xml | grep 'testdb2'
root@ytt-large:/home/ytt# docker restart dble-server
dble-server
root@ytt-large:/home/ytt# docker logs dble-server | tail -n 6
Starting dble-server...
Removed stale pid file: /opt/dble/dble.pid
wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
wait-for-it.sh: 127.0.0.1:8066 is available after 2 seconds
init shardingNode and execute template_table.sql
dble init finish
root@ytt-large:/home/ytt# mysql -uroot -p123456 -h127.0.0.1 -P8066 -e "show databases"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------+
| DATABASE |
+----------+
| testdb |
| testdb2 |
+----------+