intro
Many developers find the error “MySQL Shutdown Unexpectedly” very confusing. This SQL error seemingly comes out of nowhere and can disrupt your entire workflow — what did you do for it to come up and how do you avoid it? Read on to find out.
You’ve probably just learned that your MySQL database has been shut down unexpectedly? Well, bollocks. This error is the cause of much confusion between junior and senior DBAs alike, and that’s not without a reason — this error is associated with your application not being able to connect to your database because your database — the backbone for your application — has been shut down. How did that happen?
MySQL Shutdown Unexpectedly — Main Causes
The main causes of your MySQL database unexpectedly shutting down are as follows:
Yup, the MySQL shutdown unexpectedly error is very multifaceted. There’s no need to worry too much though — following simple advice does the trick.
MySQL Shutdown Unexpectedly — Solutions
For those after bite-sized advice, ensure that your database is running, the configuration file doesn’t mess with your server (check the logs on that one — it’s possible that your InnoDB buffer size may be too big for your server), and if that doesn’t help, restore InnoDB from a backup after deleting ibdata1 and the ib_logfile* files.
Yup, one paragraph, so many different approaches. Some also advise checking whether port 3306 (MySQL) or 3307 (MariaDB) is open and not blocked if you’re running Windows, but that shouldn’t cause many issues.
The main issue for the MySQL shutdown unexpectedly error is the over-configuration of the settings — to be fair, the most likely reason why the MySQL shutdown unexpectedly error has occurred is that your server didn’t like the way you set your InnoDB (you’re not using MyISAM as your primary storage engine, right?) settings and shut down. As easy as that. If you’ve read this blog so far, it’s likely that you’ve already squashed this error — but that doesn’t mean that other errors aren’t on the way to meet your MySQL database.
You see, the truth of the matter is that those who face this error likely face other errors, too — these may be related to an improper configuration of the max_connections
parameter, connections not being closed after you query your database and do so for hundreds, or even thousands of times, not using rate limiters where applicable, or in the worst case scenario, SQL injection or other web-based attack vectors.
Begin squashing those issues today — download a SQL client (did we tell you that we offer a free 21-day trial?), EXPLAIN
your queries by heading over to SQL Command → Execute Explain Plan or by clicking CTRL, Alt, and Enter at the same time, and examine them:

Next up, head over to the left-hand side, explore the columns, indexes, and triggers in your table (indexes and triggers will be shown in the right-hand side):

Refer to the documentation and read up on issues surrounding your use case, if that doesn’t help, consider partitioning the tables you run SELECT
queries on, read other advice applicable to your use cases by turning to TheTable when necessary, and we’ll see you in the next blog!
FAQ
What Causes the MySQL Shutdown Unexpectedly Error?
The MySQL shutdown unexpectedly error is most likely caused by the over-configuration of your database settings or, in some cases, other situations like a blocked port, or MySQL not being active in the first place.
What Should I Look Into Besides The MySQL Shutdown Unexpectedly Error?
Be mindful of whether your queries use indexes or not, partition your tables where possible, and look into security solutions offered by MySQL such as MySQL Enterprise Firewall if applicable.
Why Should I Use DbVisualizer?
DbVisualizer supports more than 50 different database technologies and is used by the most prominent companies in the engineering world. Don’t take us by our word — download and try DbVisualizer out for 21 days. For free — everything’s on us!