Search code examples
mysqlamazon-web-servicesamazon-rds

AWS MySQL connection frequently times out


I have a MySQL database in AWS (RDS), and I connect to it from command line via this command:

mysql -u _usernme_ -p_mypassword_ -h  _aws_mysql_host_ _dbname_

It connects fine, problem is, if it remains idle for 1-2 minutes, the connection dies, subsequent commands just hang. I have to kill the process and start a new one.

What configuration changes do I need to do, and where, so that it stays alive forever, just like localhost, until I expressly terminate the connection?


Solution

  • You can find out relevant timeout values as follows:

    SHOW VARIABLES LIKE '%_timeout';
    

    You might want to check to make sure wait_timeout and interactive_timeout are adequately set. Both are default to 28800 (i.e. 8 hours):

    SET GLOBAL wait_timeout = 28800;
    SET GLOBAL interactive_timeout = 28800;