ubuntu安裝nacos,整合mysql連線異常解決
阿新 • • 發佈:2020-08-24
環境: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 more124 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 failure152 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新增,設定密碼,然後用root連結,問題解決!
修改root使用者的的密碼如下:
這裡是關鍵點,由於mysql5.7沒有password欄位,密碼儲存在authentication_string欄位中,password()方法還能用
在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