我正在开发一个 Docker 应用程序,它使用 MySQL 来存储非常大的数据库(这是由于遗留原因)。 这个安装在主机上。
今天我正在做我已经做了 1 或 2 个月的普通工作,突然间我无法再与我的数据库通信。
数据库的 uri 几个月来一直是一样的:
jdbc:mysql://localhost:3306/dbname?verifyServerCertificate=false&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
一旦我尝试从我在虚拟机上运行的应用程序连接到数据库,我就会收到:
java.sql.SQLException: Cannot create PoolableConnectionFactory (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.)
...
Caused by: java.net.ConnectException: Connection timed out
有罪的代码是这样的:
private static boolean checkForExistence(String dbName) {
boolean exists = false;
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(JDBC_DRIVER); //com.mysql.cj.jdbc.Driver
dataSource.setUrl(this.url); //that's the uri provided before
dataSource.setUsername(USER);
dataSource.setPassword(PASS);
Connection conn = null;
Statement stmnt = null;
ResultSet dbs = null;
try {
conn = dataSource.getConnection(); //And this is the line that triggers the exception.
System.out.println(conn!=null);
dbs = conn.getMetaData().getCatalogs();
while(dbs.next() && !exists)
if(dbs.getString(1).equals(dbName))
exists = true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(conn != null)
conn.close();
if(stmnt != null)
stmnt.close();
if(dbs != null)
dbs.close();
if(dataSource != null)
dataSource.close();
} catch (SQLException e) {
logger.error(e.getMessage());
return exists;
}
}
return exists;
}
我尝试了以下操作:
telnet <public ip of the VM> 3306 -> 连接超时mysql -h<public ip of the VM> -u user -p -> ERROR 2003 (HY000): Can't connect to MySQL server on 'remoteHostname.com' (110) nc localhost 3306 -> 我可以进去。mysql -h127.0.0.1 -u user -p -> 我可以进去。mysql -h<public ip address> -u user -p -> 我可以进去。如果我运行 netstat -tulpn | grep 3306我得到了:
tcp6 0 0 :::3306 :::* LISTEN -
tcp6 0 0 :::33060 :::* LISTEN -
这是 my.cnf :
[mysqld]
default_authentication_plugin=mysql_native_password
datadir=/local/user/mysql
socket=/var/lib/mysql/mysql.sock
general_log_file=/var/log/mysql.log
general_log=1
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
我可以通过 PhpMyAdmin 连接到数据库,但我认为这是因为它使用的是 Socket 连接。
如果我检查 /var/log/mysql.log和 /var/log/mysqld.log (这是关于错误的)没有任何证据。基本上,当我尝试连接时,它们不会显示任何内容。
编辑: 如果我使用相同的设置连接到我的本地机器 mysql 实例,一切正常。那么这可能与网络问题有关吗?或者 VM 的 mysql 实例由于某种原因不再接受 tcp 连接?
重新编辑:
打卡/var/log/messages我发现主机磁盘空间不足。从那时起,界面docker0继续blocked state然后 disabled state环形。
配置:
最佳答案
在问题的重新编辑部分,我指定了新的细节。我仍然无法使用旧配置正确运行应用程序,但在 docker run 中使用 --network=host 参数可以解决问题。
这只是一个解决方法。我会用更多信息更新这个问题。
关于java - MySQL - docker 容器和 MySQL 之间突然出现 "Communications link failure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53816274/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub