ubuntu安装nacos,整合mysql连接异常解决

环境:ubuntu 18.04

mysql:5.7.30

nacos:1.1.4

nacos连接异常提示:

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNested    Exception: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
 33     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81).....
.............
............
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. At    tempted reconnect 3 times. Giving up.)
117     at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
118     at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)                                                        
119     at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
120     at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
121     at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
122     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
123     ... 82 more
124 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconne    ct 3 times. Giving up.
125     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)....
............
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
152 
153 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
154     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
155     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
156     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
157     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
158     at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
159     at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036)
160     at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
161     at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
162     at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2085)
163     ... 101 more
164 Caused by: java.net.ConnectException: Connection refused (Connection refused)....
.......

 

网上查了各种方法都没用,最后还以是不是自己的mysql有问题,因为ubuntu安装mysql时是没有让输入密码的,所以root不用密码也能登录。

然后尝试创建新用户nacos,开放所有权限,还是没用。

最后给root添加,设置密码,居然解决了问题,用新建的nacos也可以用了

 

修改root用户的的密码如下:

这里是关键点,由于mysql5.7没有password字段,密码存储在authentication_string字段中,password()方法还能用

在mysql中执行下面语句修改密码

ubuntu安装nacos,整合mysql连接异常解决
show databases; 
use mysql; 
update user set authentication_string=PASSWORD("yourpassword") where user=‘root‘; 
update user set plugin="mysql_native_password"; 
flush privileges; 
quit;
View Code

 

ubuntu安装nacos,整合mysql连接异常解决

上一篇:如何将基础信息表,导入到另一些张表中,另一个数据库的表中呢?


下一篇:sql语法