我在码头上设置了 mysql 和 apache 超集并通过桥接网络连接,SQLAlchemy URI 是什么?

I have mysql and apache superset setup on dockers and connected by a bridge network, what will theSQLAlchemy URI be?

我拉取了官方超集镜像:

git clone https://github.com/apache/incubator-superset.git

然后将 MYSQL 客户端添加到 requirements.txt

cd incubator-superset
touch ./docker/requirements-local.txt
echo "mysqlclient==1.4.6" >> ./docker/requirements-local.txt
docker-compose build --force-rm
docker-compose up -d

之后我制作了 MYSQL 容器

docker run --detach --network="incubator-superset_default" --name=vedasupersetmysql --env="MYSQL_ROOT_PASSWORD=vedashri" --publish 6603:3306 mysql

然后 Mysql 连接到 Superset Bridge。

网桥如下:

docker inspect incubator-superset_default
[
    {
        "Name": "incubator-superset_default",
        "Id": "56db7b47ecf0867a2461dddb1219c64c1def8cd603fc9668d80338a477d77fdb",
        "Created": "2020-12-08T07:38:47.94934583Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "07a6e0d5d87ea3ccb353fa20a3562d8f59b00d2b7ce827f791ae3c8eca1621cc": {
                "Name": "superset_db",
                "EndpointID": "0dd4781290c67e3e202912cad576830eddb0139cb71fd348019298b245bc4756",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            },
            "096a98f22688107a689aa156fcaf003e8aaae30bdc3c7bc6fc08824209592a44": {
                "Name": "superset_worker",
                "EndpointID": "54614854caebcd9afd111fb67778c7c6fd7dd29fdc9c51c19acde641a9552e66",
                "MacAddress": "02:42:ac:13:00:05",
                "IPv4Address": "172.19.0.5/16",
                "IPv6Address": ""
            },
            "34e7fe6417b109fb9af458559e20ce1eaed1dc3b7d195efc2150019025393341": {
                "Name": "superset_init",
                "EndpointID": "49c580b22298237e51607ffa9fec56a7cf155065766b2d75fecdd8d91d024da7",
                "MacAddress": "02:42:ac:13:00:06",
                "IPv4Address": "172.19.0.6/16",
                "IPv6Address": ""
            },
            "5716e0e644230beef6b6cdf7945f3e8be908d7e9295eea5b1e5379495817c4d8": {
                "Name": "superset_app",
                "EndpointID": "bf22dab0714501cc003b1fa69334c871db6bade8816724779fca8eb81ad7089d",
                "MacAddress": "02:42:ac:13:00:04",
                "IPv4Address": "172.19.0.4/16",
                "IPv6Address": ""
            },
            "b09d2808853c54f66145ac43bfc38d4968d28d9870e2ce320982dd60968462d5": {
                "Name": "superset_node",
                "EndpointID": "70f00c6e0ebf54b7d3dfad1bb8e989bc9425c920593082362d8b282bcd913c5d",
                "MacAddress": "02:42:ac:13:00:07",
                "IPv4Address": "172.19.0.7/16",
                "IPv6Address": ""
            },
            "d08f8a2b090425904ea2bdc7a23b050a1327ccfe0e0b50360b2945ea39a07172": {
                "Name": "superset_cache",
                "EndpointID": "350fd18662e5c7c2a2d8a563c41513a62995dbe790dcbf4f08097f6395c720b1",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            },
            "e21469db533ad7a92b50c787a7aa026e939e4cf6d616e3e6bc895a64407c1eb7": {
                "Name": "vedasupersetmysql",
                "EndpointID": "d658c0224d070664f918644584460f93db573435c426c8d4246dcf03f993a434",
                "MacAddress": "02:42:ac:13:00:08",
                "IPv4Address": "172.19.0.8/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "incubator-superset",
            "com.docker.compose.version": "1.26.0"
        }
    }
]

我应该如何形成 SQLAlchemy URI? 我试过了 mysql://user:password@8088:6603/数据库名

但是当我输入这个 URI 时它显示连接错误。

如果有任何相关文档,那也会有所帮助。

我对 Docker 没有太多经验,但我认为您不应该使用 8088 作为 MySQL 数据库的主机。

尝试使用 mysql://user:password@172.19.0.8:6603/database-name 作为 URI。

该问题与超集或网络无关。您配置了正确的网络,但尚未在 MySQL docker 图像上启用 default-authentication-plugin。由于此错误,控制台上显示的是

 Plugin caching_sha2_password could not be loaded:

重现:

from sqlalchemy import create_engine
engine = create_engine('mysql://root:sample@172.19.0.5/mysql')
engine.connect()

错误日志:

   sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1045, 'Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory')
    (Background on this error at: http://sqlalche.me/e/13/e3q8)

解决问题:

使用 default-authentication-plugin

创建 MySQL 图像
docker run --detach --network="incubator-superset_default" --name=mysql --env="MYSQL_ROOT_PASSWORD=sample" --publish 3306:3306 mysql --default-authentication-plugin=mysql_native_password 

Superset 已有用户定义的桥接网络,因此您可以使用两种格式

mysql://root:sample@mysql/mysql
mysql://root:sample@172.19.0.5/mysql