mysql-docker容器和mysql之间突然出现“通信链路故障”

fslejnso  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(387)

我正在开发一个docker应用程序,它使用mysql存储非常大的数据库(这是由于遗留的原因)。这个安装在主机上。
今天我做了一两个月的普通工作,突然间我不能再和数据库通信了。
db的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) 从vm内部: nc localhost 3306 ->我可以进去。
从vm内部: mysql -h127.0.0.1 -u user -p ->我可以进去。
从vm内部: 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连接到db,但我认为这是因为它使用了套接字连接。
如果我都查的话 /var/log/mysql.log 以及 /var/log/mysqld.log (这是关于错误的)没有任何证据。基本上,当我尝试连接时,它们不会显示任何内容。
编辑:如果我使用相同的设置连接到mysql的本地机器示例,一切都正常。那么这可能与网络问题有关吗?或者云主机的mysql示例由于某种原因不再接受tcp连接?
重新编辑:签入 /var/log/messages 我发现主机的磁盘空间用完了。从那时起,界面 docker0 继续进行 blocked state 然后 disabled state 循环。
配置:
带有rhel7的远程vm
32核cpu
64gb内存
mysql 8.0.13-mysql社区服务器-gpl
phpmyadmin 4.8.4

4sup72z8

4sup72z81#

在问题的重新编辑部分,我指定了新的细节。我仍然无法使用旧配置正确运行应用程序,但使用 --network=host 中的参数 docker run 我成功了。
这只是一个解决办法。我将用更多的信息更新这个问题。

相关问题