Lost connection to MySQL server during query


In this blog post, I will show you how to troubleshoot and resolve connectivity issues with Aurora MySQL RDS Instance.

 

Problem Statement 

We were unable to establish connection with one of our Aurora MySQL RDS data store. I use MySQL Workbench locally to connect to the AWS databases and I was able to connect to every other database except this one. Please find below the error details —

Lost connection to MySQL server during query

Failed to connect

Please:
1 Check that MySQL is running on address *****
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user admin has rights to connect to ***** from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for ***** connecting from the host address you’re connecting from.

Reading through the above seems like there is a connection issue between the MySQL client and the Database server and the connection timed out before returning data.

 

Is the issue specific to MySQL Workbench?

  • Open the MySQL Workbench Preferences.
  • Check if the SSH Timeout and DBMS Timeout value is set to only a few seconds.
  • Try to increase the default value of the connection timeouts.
  • Save the settings, close the MySQL Workbench and reopen the connection to see if you are able to connect to the database.

Workbench Preferences

 

DBMS Timeout

 

Did you try rebooting the Database instance?

Rebooting a DB instance restarts the database engine service. It will result in a momentary outage though.

Reboot Database

You can also reboot the database instance using AWS CLI —

aws rds reboot-db-instance –db-instance-identifier databasename –profile live –region us-east-1


Make sure to check the Database status and confirm it is ‘Available’

Database Status

 


Did you check the Cloudwatch Metrics for the Database Cluster?

You can check the database Cloudwatch metrics – especially DatabaseConnections, EngineUptime and UpdateThroughput as a troubleshooting step.

                       
          

                       

In this case seems like after an engine restart on 8/11, there has been some connectivity issues.


Did you check the Database Error Logs?

You can view, download, and watch database logs using the Amazon RDS console.

RDS Error Logs

This is where I was able to figure out the root cause of the connectivity failure. Evidently there was an error in the logs stating – ‘init_connect command failed’

Init Connect Command Failed

Init_connect — This parameter defines a string for the server to run for each client that connects. There is no default value for this parameter. The string consists of one or more SQL statements, separated by semicolons.

init_connect

I had an incorrect value mentioned  the ‘init_connect’ parameter which caused the issue. Once I corrected the value and applied the changes, I was able to connect to the database.

 

Conclusion 

Summarizing this blog post, there are a number of things you can do to troubleshoot connectivity issues with your AWS RDS database while trying to connect locally via MySQL Workbench —

  1. Confirm the issue is not specific to MySQL Workbench
  2. Reboot the Database instance
  3. Check the Cloudwatch Metrics for the Database Cluster
  4. Check the Database Error Logs

Check out my other recent blog posts around troubleshooting issues —

Troubleshooting Issues with AWS Database Migration Service

Flyway Error: Found non-empty schema(s) without schema history table

Tomcat Error – java.net.BindException: Address already in use

Resolving Gradle issues in IntelliJ IDEA

Synchronize Gradle projects with workspace failed



Categories: AWS, MySQL

Tags: ,

1 reply

Trackbacks

  1. The MySQL server is running with the -read-only option so it cannot execute this statement - dotnetvibes

Leave a Reply