MySQL 1182: Connection was closed.

  1. Check the MySQL server logs. Run `tail -n 100 /var/log/mysql/error.log` to see recent error messages that might indicate why the connection was closed.



  1. Verify MySQL server is running: `sudo systemctl status mysql` or `mysqladmin -u root -p status` to ensure the MySQL service is active.



  1. Check for network issues: Use `ping` or `traceroute` to ensure there's network connectivity between your application server and the MySQL server.



  1. Examine the `maxconnections` setting: Run `SHOW VARIABLES LIKE "maxconnections";` to see if you're hitting the maximum number of connections allowed.



  1. Inspect open connections: Execute `SHOW STATUS LIKE "Threadsconnected";` to see how many connections are currently open and compare it with the `maxconnections` value.



  1. Review your application code or configuration to ensure it's correctly managing database connections, such as properly closing them when done.



  1. If using a pool of connections, check its configuration to ensure it matches the capabilities of your MySQL server, specifically the `max_connections` setting.



  1. Investigate for any ongoing large queries that may be causing timeouts or locking issues: `SHOW FULL PROCESSLIST;` to see current executing queries.



  1. Increase the connection timeout settings if necessary, by adjusting `waittimeout` and `interactivetimeout`: `SET GLOBAL waittimeout = 28800;` and `SET GLOBAL interactivetimeout = 28800;` for a start, adjusting values based on your needs.



  1. If possible, temporarily increase `maxconnections` to see if the problem persists: `SET GLOBAL maxconnections = 1000;` (adjust the number based on your server's capability and needs).



Remember to revert any temporary changes that are not suitable for your production environment after testing.

Master

MySQL

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MySQL

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid