Bobcares

Digitalocean – MySQL keeps crashing – Here’s how to fix it!

by | Dec 12, 2018

Does your website often show “Error establishing a database connection” message ?

If the answer is Yes, a possible reason could be MySQL service crash on your DigitalOcean Droplet.

Usually, the exact reason for MySQL crash varies from lack of resources on the server to bad website scripts.

At Bobcares, we help customers to fix MySQL service in droplets as part of our Dedicated Support Services for Web Hosts.

Today, we’ll see the common reasons that cause MySQL crashing and how we fix them.

 

Reasons for MySQL crashing in DigitalOcean Droplet

A MySQL server crash is really critical because all your websites will be affected by this. Therefore, it needs a quick solution.

For this, we first need to find out the reason for MySQL failure.

Let’s have a look at the various reasons that would crash the MySQL service on the Droplet.

 

1. Buggy scripts

From our experience in managing DO Droplets, we often see buggy php scripts overloading the server. These scripts have bad mysql queries that would consume server resources. Additionally, they just keep on running on the server without giving a result.

Similarly, in WordPress websites, often certain plugins cause MySQL to fail. And that causes database errors on the website.

 

2. Lack of server resources

Yet another reason for MySQL crash could be lack of server resources.

This happens mainly when the minimal configuration Droplets provided by Digital Ocean are stuffed with too many websites. These Droplets would have only a total 512MB memory. This low memory will not be enough to handle high traffic websites, manage server processes, etc. As a result, it results in ‘Out of Memory’ issues in droplet.

When the physical memory (RAM) is full, PHP scripts use a buffer memory called “Swap” to process the request. If we plan to use this buffer space, we need to assign this Swap space during the initial set up of Droplet.

When adequate swap space is not created in the Droplet, lack of memory can again lead to MySQL crash.

 

3. Malicious attacks

Occasionally, the high resource usage by MySQL would not be due to valid website access. We often see that attacks involving xmlrpc.php file of WordPress. In this attack, hacker tries to break into the admin panel of WordPress using too many hits to the website.

The server eventually will not be able to handle the large number of requests and can crash.

 

4. Broken databases

Similarly, broken databases also can cause Database errors in the Website. This happens mainly when the database files becomes corrupt. Often, disk full issues, permission problems can also lead to MySQL crash.

 

How to fix MySQL crashing in DigitalOcean Droplets?

We’ve now seen the various reasons that would crash MySQL on your Droplet.

Now, let’s see how our Support Engineers resolve these MySQL crash on Droplets. Depending on the reason for crash, the fix also varies. Let’s see these fixes in detail.

 

1. Allocate adequate server resources

This involves allocating adequate amount of resources on the droplet. Again, this largely depends on the functionality of the server. The Droplet should have enough processing power, memory, swap space, disk space, etc. on the server.

By default, the DigitalOcean Droplets do not have swap space created. Here, our Hosting Support Experts analyze the resources on the server and reserve adequate percentage of memory for swap. For example, in a Droplet with 4GB memory, depending on the type of websites, a swap space of 1GB would be ideal.

However, if there is consistent use of swap space on the server, we advise customers to permanently upgrade the memory of Droplet.

 

2. Service optimization

Even though there is enough resources on the server, wrong MySQL configuration often cause crash. That’s why, on a Droplet with frequent MySQL crash, our Security Engineers enable slow queries in MySQL. And, it will be logged to the mysql log file available at /var/log/mysql/log-slow-queries.log. This helps us to identify the specific sites that cause the problem.

If the problem is with the website script, we help website owners to fix it. This applies to the trouble causing plugins in WordPress websites as well.

Additionally, we optimize the MySQL service variables like max_connections, query_cache_limit, table_cache, etc.

For the best results, we extend this optimization to the web server too. This involves changes like restricting values such as  Max_clients, StartServers in Apache configuration, choosing the correct processing module, etc.

 

3. Prevent malicious attacks

When we see an attack on a Droplet, we implement proper firewall to protect these malicious attacks. For instance, in xmlrpc attack, we disable xmlrpc method on the server as a whole, install plugins to stop attack, etc.

Additionally, our Security Experts suggest customers to proactively set proper defending mechanisms in the Droplets.

 

4. Periodic Database Check

It is worth to do a periodic check of the databases running on the server. This would help us to track and repair corrupt tables if any. Our Expert Engineers do a scheduled database check with the help of cron jobs. This includes a check of the server disk space usage, MySQL log file size, etc. as well. Thus, we can omit the MySQL crash due to disk full issues.

 

Conclusion

MySQL crashing in DigitalOcean Droplets happen mainly due to scarcity of resources, bad MySQL configuration, buggy scripts, etc. Today, we’ve seen how our Support Engineers analyze the database server crash and fix it.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.