nacos配置中心连接mysql8.0

nacos配置中心连接mysql8.0

nacos连接mysql5.7正常,但是连接mysql8.0(mysql5.8)就提示错误。

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)

连接mysql5.7没问题。说明连接驱动版本有问题(为什么直接这么说呢,因为之前项目中mysql升级遇见过相同问题)。

把Nacos 自带mysql-connector-java 版本升级以下就可以了,从5.1.34升级到5.1.47。

1、首先 git clone https://github.com/alibaba/nacos.git

 

2、如果速度慢,设置hosts。

修改 C:\Windows\System32\drivers\etc。

151.101.185.194 github.global.ssl.fastly.net
192.30.253.112 github.com

 

3、接着下载后执行

先把版本修改

《nacos配置中心连接mysql8.0》

 

然后执行打包命令

cd nacos/ mvn -Prelease-nacos clean install -U

ls -al distribution/target/

// change the $version to your actual path

cd distribution/target/nacos-server-$version/nacos/bin

 

修改启动配置文件

nacos\distribution\target\nacos-server-1.0.1\nacos\conf\application.properties

末尾添加:

spring.datasource.platform=mysql

db.num=1

db.url.0=jdbc:mysql://localhost:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true

db.user=nacos_devtest

db.password=youdontknow

 

接着建库,执行mysql脚本

\nacos\distribution\target\nacos-server-1.0.1\nacos\conf\nacos-mysql.sql

接着你就可以启动bin文件夹下的 startup.cmd

浏览器访问http://127.0.0.1:8848/nacos

默认账号和密码:nacos

 

参考链接;https://nacos.io/zh-cn/docs/what-is-nacos.html

点赞