# Fixing WordPress crashes due to MySQL out of space

- Link: https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/
- Published: 2021-08-07T10:04:59-07:00
- Author: rich

OK I get this about three weeks or so on our new DigitalOcean Droplet running WordPress.
The good news is the JetPack does inform you when it dies.

On Bluehost, this basically has never happened. A restart of the droplet seems to
help, but it would be good to figure out what is going on.

This is a very common problem and [WP Beginner](https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/)
has a diagnostic set.

 1. See if your host is up. A quick ssh can check to make sure the Droplet is still
    running.
 2. Does the problem occur with the administrative interface `/wp-admin/`. If it says
    the database needs to be repaired, then you can add `definte('WP_ALLOW_REPAIR',
    true` to `wp-config.php` and you can fix it and then go to `http://yoursite.com/
    wp-admin/maint/repair.php`
 3. Check your WP-Config.php file and if you didn’t change your database password (
    why would you?), then you make need to change the DB_Host from localhost to `define('
    DB_HOST', '127.0.0.1:8889` but this didn’t work either. Or try 3306
 4. See if MySQL Server is up and running. You need a sample application that tests
    this.

`<?php`

`$link` `= mysqli_connect('localhost', 'username', 'password');`

`if` `(!$link) {`

`die('Could not connect: '` `. mysqli_error());`

`}`

`echo` `'Connected successfully';`

`mysqli_close($link);`

`?>`

If this ends with could not connect then MySQL is down for some reason.

## How to debug Mysql

OK, so that wasn’t of much help, time to figure out what to do when Mysql is unavailable.
[DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-access-mysql-error-logs)
has a good tutorial on this:

 1. Look at the error log, they are kept in `var/log/mysql/error.log` and it was pretty
    revealing, the last line was `/usr/sbin/mysqld: Shutdown complete`
 2. Looking up it says, `Failed to initialize builtin plugins` and then it shows that
    InnoDB failed because it could not allocate buffer memory.

So I”m wondering if my 1GB tiny WordPress Droplet is too small and [StackOverflow](https://www.digitalocean.com/community/questions/most-efficient-setup-for-wordpress)
confirms that it will not run in a $5/month droplet because of memory shortages.
You need more RAM and you should allocate a Block Volume.

## Restarting Mysql

To test this, you can just restart Mysql with `service mysql restart` and see if
it works It won’t tell you what is really wrong, but will get you going again.

## No Swapfile for WordPress Droplet installations

Ok, part of the problem seems to be that there is [no swapfile](https://askubuntu.com/questions/927854/how-do-i-increase-the-size-of-swapfile-without-removing-it-in-the-terminal)
for the DigitalOcean droplet. That is `swapon -s` reveals nothing and there is no`/
swapfile`

If you already have a swapfile, here is how to increase the size, first turn off
the swap and then first disable the swapfile and delete. See https://askubuntu.com/
questions/1075505/how-do-i-increase-swapfile-in-ubuntu-18-04

    ```
    sudo swapoff /swapfile sudo rm  /swapfile
    ```

The other thing it could be is that Apache is overloading because of too much access
to XMLRPC, but that doesn’t seem like the problem. With Ubuntu 18.04, a swapfile
can be just about anything, but by convention, `/swapfile` is used, so to create
one, it looks like to create a 2GB swapfile

    ```
    dd if=/dev/zero of=/swapfile count=2K bs=1M mkswap /swapfile sudo chown root:root /swapfile sudo chmod 600 /swapfile sudo swapon /swapfile
    ```

### Share this:

 * [  Mastodon ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=mastodon)
 * [  LinkedIn ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=linkedin)
 * [  Facebook ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=facebook)
 * [  WhatsApp ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=jetpack-whatsapp)
 * [  Email ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?subject=%5BShared%20Post%5D%20Fixing%20WordPress%20crashes%20due%20to%20MySQL%20out%20of%20space&body=https%3A%2F%2Ftongfamily.com%2F2021%2F08%2F07%2Ffixing-wordpress-crashes-due-to-mysql-out-of-space%2F&share=email)
 * [More](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/#)

 * [  Telegram ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=telegram)
 * [  Print ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/#print?share=print)
 * [  Pinterest ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=pinterest)
 * [  Tumblr ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=tumblr)
 * [  X ](https://tongfamily.com/2021/08/07/fixing-wordpress-crashes-due-to-mysql-out-of-space/?share=twitter)

### Like this:

Like Loading…
