如何查看/更改MySQL连接超时设置?

问题描述:

我有一个java程序,当我登录时,大约600,000毫秒(我实际上尝试了几次,它总是~600,000,这就是为什么我认为在某处设置超时600,000毫秒)我的数据库连接崩溃了我的程序不再有效(它总是需要连接到数据库)。它给了我通信链接失败错误。我这是我的mysql连接设置:

I have a java program, when i log in, after ~600,000 milliseconds (i actually tried several times, and its always ~600,000, thats why i think theres somewhere set up a timeout for 600,000 miliseconds) my database connection crashes and my program no longer works (it always needs to be connected to database). It gives me Communication link failure error. I Here are my mysql connection settings:

import java.sql.*;
import javax.swing.*;
public class mysqlconnect {
    Connection conn = null;
    public static Connection ConnectDb()    {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://server_name/database_name","user_name","user_password");
            return conn;
        }catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Cant connect to db");
            return null;
        }
    }
}

我尝试添加?autoReconnect = true & tcpKeepAlive 到我的代码,但没有运气。有没有办法去phpmyadmin并在那里更改一些设置(增加超时时间)?

I tried adding ?autoReconnect=true & tcpKeepAlive to my code, but no luck. Is there any way to go to phpmyadmin and change some setting there (increase the timeout time)?

SET SESSION wait_timeout = 999999;//or anything you want

从mysql命令行增加超时值。为了能够看到价值:

From mysql command line that will increase the timeout value. To be able to see the value:

SHOW VARIABLES LIKE 'wait_timeout';