当前位置:   article > 正文

docker 启动 nacos 连接本地数据库 踩坑_caused by: com.alibaba.nacos.api.exception.nacosex

caused by: com.alibaba.nacos.api.exception.nacosexception: nacos server did

docker logs -f containter_id

Caused by: com.alibaba.nacos.api.exception.NacosException: Nacos Server did not start because dumpservice bean construction failure :
No DataSource set
  • 1
  • 2

进一步查看 容器内错误日志 /home/nacos/logs/nacos.log

报错开始行

2022-11-10 16:03:34,323 ERROR HikariPool-1 - Exception during pool initialization.

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
  • 1
  • 2
  • 3

后面找到一行关键错误

Caused by: com.mysql.cj.exceptions.CJException: Access denied for user 'root'@'host.docker.internal' (using password: YES)
  • 1

一般来讲本地数据库是不会放开远程连接的 所以我这边是新建一个用户 并授权 开始远程连接
创建nacos用户

create user 'nacos'@'%' identified by '123456';
  • 1

将nacos数据管理权限授权给nacos

grant all privileges on nacos.* to `nacos`@'%';
  • 1

将新配置刷新到缓存中,这样就不用重启数据库

flush privileges;
  • 1

修改配置
application.properties文件

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.16.102:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=123456
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

再次启动
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/159654
推荐阅读
相关标签
  

闽ICP备14008679号