从主机网络的sql客户端连接到docker容器时出错

w8rqjzmb  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(237)

我正在用compose file触发mysql:

version: "3"
services:
  my-sql:
    image: mysql
    container_name: my-sql
    ports:
     - 3306:3306
    environment:
     MYSQL_ROOT_PASSWORD: passw0rd 
     MYSQL_USER: dbuser
     MYSQL_PASSWORD: pass1234
     MYSQL_DATABASE: connect_test

按以下方式查找容器的IP地址:

root@sevenos:~# docker inspect my-sql | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "",
                    "IPAddress": "172.18.0.2",

当我与 my-sql client 在容器外,我得到如下错误:

root@sevenos:~# mysql -uroot -ppassw0rd -h 172.18.0.2 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be 
loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
eufgjt7s

eufgjt7s1#

您可以使用以下命令初始化docker以加载默认身份验证插件:

mysql:
    image: mysql
    container_name: mysql
    command: mysqld --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
        - MYSQL_ROOT_PASSWORD=root
    volumes_from:
        - mysql-data
    ports:
        - "3306:3306"

在运行之前,必须删除所有mysql卷:

docker-compose rm
docker volume rm list_of_your_volumes
docker-compose up

有关更多详细信息,请参阅:https://github.com/passbolt/passbolt_docker/issues/103

相关问题