错误详情: 数据库确认可以连接上。 并且查看了Seata容器中的MySQL连接的驱动jar包(mysql-connector-java-5.1.35.jar),版本没有问题。使用的MySQL版本是5.7。 我是在容器中的这个文件夹看的驱动版本: 我把容器中的配置文件通过卷挂载到了本地,并且设置了registry的type为nacos,config的type也为nacos。 并且通过官网的指引,去GitHub上拿到了那个config.txt配置文件,并且在nacos中发布了这个配置,以下是我的dataId: 我确认每次启动时,seata是可以读取到里面的配置的,因为我试过更改其中的"store.db.url"这一项,于是启动报错的信息中的url也变成我改之后的那个了。 数据库的用户名和密码也没有错误(使用别的客户端连接过),ip和port也无误。 再展示一下我在nacos中对store.db.url的配置(和官网指引是一样的): 并且我也创建了对应的数据库(并且命名为seata)和表。 再展示一下完整的错误栈: 19:30:43.686 ERROR --- [ main] com.alibaba.druid.pool.DruidDataSource : init datasource error, url: jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true ==> com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212] at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.MysqlIO. (MysqlIO.java:338) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2237) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl. (ConnectionImpl.java:794) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.JDBC4Connection. (JDBC4Connection.java:44) ~[mysql-connector-java-5.1.35.jar:5.1.35] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212] at com.mysql.jdbc.Util.handleNewInstance(Util.java:389) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1644) ~[druid-1.1.23.jar:1.1.23] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710) ~[druid-1.1.23.jar:1.1.23] at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:912) [druid-1.1.23.jar:1.1.23] at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1378) [druid-1.1.23.jar:1.1.23] at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1374) [druid-1.1.23.jar:1.1.23] at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98) [druid-1.1.23.jar:1.1.23] at io.seata.server.storage.db.store.LogStoreDataBaseDAO.queryTableStructure(LogStoreDataBaseDAO.java:461) [classes/:na] at io.seata.server.storage.db.store.LogStoreDataBaseDAO.initTransactionNameSize(LogStoreDataBaseDAO.java:445) [classes/:na] at io.seata.server.storage.db.store.LogStoreDataBaseDAO. (LogStoreDataBaseDAO.java:106) [classes/:na] at io.seata.server.storage.db.store.DataBaseTransactionStoreManager. (DataBaseTransactionStoreManager.java:96) [classes/:na] at io.seata.server.storage.db.store.DataBaseTransactionStoreManager.getInstance(DataBaseTransactionStoreManager.java:81) [classes/:na] at io.seata.server.storage.db.session.DataBaseSessionManager.init(DataBaseSessionManager.java:77) [classes/:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.initInstance(EnhancedServiceLoader.java:564) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.createNewExtension(EnhancedServiceLoader.java:395) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.getExtensionInstance(EnhancedServiceLoader.java:388) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.loadExtension(EnhancedServiceLoader.java:356) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.load(EnhancedServiceLoader.java:245) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.access$200(EnhancedServiceLoader.java:190) [seata-common-1.4.2.jar:na] at io.seata.common.loader.EnhancedServiceLoader.load(EnhancedServiceLoader.java:82) [seata-common-1.4.2.jar:na] at io.seata.server.session.SessionHolder.init(SessionHolder.java:97) [classes/:na] at io.seata.server.Server.main(Server.java:80) [classes/:na] Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_212] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_212] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_212] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_212] at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213) ~[mysql-connector-java-5.1.35.jar:5.1.35] at com.mysql.jdbc.MysqlIO. (MysqlIO.java:297) ~[mysql-connector-java-5.1.35.jar:5.1.35] ... 33 common frames omitted
问题解决了,我的配置使用的是本地ip(localhost),但是如果我使用容器部署seata,实际要使用的是mysql容器的ip地址(我也使用容器部署了mysql)。把配置中的ip改为容器ip即可。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。