gpt4 book ai didi

java - 不允许主机 '172.23.0.9' 连接到此 MariaDB 服务器

转载 作者:行者123 更新时间:2023-11-30 05:59:55 25 4
gpt4 key购买 nike

嘿嘿

Spring 设置

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url= jdbc:mysql://vetdb:3306/vetdb?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.platform=mysql

spring.datasource.initialize=true
spring.jpa.show-sql=false

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

spring.jmx.default-domain=TierarztDatenController
endpoints.jmx.uniquie-names=true

Docker 组合

  vetdb:
container_name: vetdb
hostname: vetdb
image: mariadb
restart: always
command: --default-authentication-plugin=mysql_native_password --innodb-flush-method=O_DSYNC --innodb-use-native-aio=0 --log_bin=ON
environment:
MYSQL_ROOT_PASSWORD: ${VET_DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${VET_DB_NAME}
MYSQL_PASSWORD: ${VET_DB_PASSWORD}
MYSQL_ROOT_HOST: '%'
volumes:
# - "${VET_DB_PATH}/mysql-conf:/etc/mysql/conf.d"
- "${VET_DB_PATH}:/var/lib/mysql"
- "${VET_DB_PATH}/mysql-log:/var/log/mysql"

.env

VET_DB_PATH=./dockervolumes/microservices/VET/db
VET_DB_NAME=vetdb
VET_DB_ROOT_PASSWORD=root
VET_DB_PASSWORD=root

Exception: `java.sql.SQLException: null, message from server: "Host '172.23.0.9' is not allowed to connect to this MariaDB server"`

我添加了MYSQL_ROOT_HOST: '%'允许每个人连接到数据库,但它不起作用我尝试使用 config-file.cnf包含bind-address = 0.0.0.0但没有成功

有趣的是,在我今天重新启动容器之前,一切都运行良好,并且我在 3 天内没有更改此服务

我尝试查看名称/密码是否 = root 工作

$ docker exec -it vetdb bash
root@vetdb:/# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

但是没有密码的 root 可以工作(在容器内)

root@vetdb:/# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.3.9-MariaDB-1:10.3.9+maria~bionic-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

如果我删除spring.datasource.password=root或将其设置为 spring.datasource.password=那么它会导致相同的异常

我做错了什么?

最佳答案

我将环境变量更改为这个

    environment:
- "MYSQL_ROOT_PASSWORD=${VET_DB_ROOT_PASSWORD}"
- "MYSQL_DATABASE=${VET_DB_NAME}"
- "MYSQL_ROOT_HOST=%"

并删除所有内容重新运行它,它起作用了

docker-compose down
docker rm -f $(docker container ls -aq)
docker-compose rm -v
docker volume prune
docker system prune
rm dockerdockervolumes/ -rf

成功了

关于java - 不允许主机 '172.23.0.9' 连接到此 MariaDB 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52442598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com