Question

MySQL crashes when uploading images in Wordpress (Ubuntu 20.04)

Posted January 10, 2021 656 views
MySQLApacheUbuntu 20.04

I have a 1GB RAM droplet with a single Wordpress site on it on Apache. It gets no visitors.

Uploading images through the WP media uploader will crash MySQL. This is more likely if I upload more images. Rebooting the server is required to fix things again. Nothing else causes the server to crash.

I was thinking it could be to do with a lack of RAM but I run another website on a 1GB droplet with Ubuntu 16.04 and don’t get this issue. Does 20.04 perform worse with Wordpress?

If I run top I normally have 65 “free” and 100-200 “available Mem”.

When the crash occurs, MySQL error log prints:

2021-01-10T00:53:30.767263Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-01-10T00:53:30.767531Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-01-10T00:53:30.807432Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22-0ubuntu0.20.04.3'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
2021-01-10T00:53:34.140376Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22-0ubuntu0.20.04.3) starting as process 18098
2021-01-10T00:53:34.154228Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-10T00:53:34.778531Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-10T00:53:35.239850Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2021-01-10T00:53:35.594495Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2021-01-10T00:53:35.630346Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2021-01-10T00:53:47.286121Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-01-10T00:53:47.286781Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-01-10T00:53:47.338498Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22-0ubuntu0.20.04.3'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
2021-01-10T00:53:58.940189Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22-0ubuntu0.20.04.3) starting as process 18166
2021-01-10T00:53:59.023721Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-10T00:54:16.018441Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22-0ubuntu0.20.04.3) starting as process 18204
2021-01-10T00:54:16.089162Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-10T00:54:52.357857Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.

Apache error log doesn’t contain anything to do with the issue.

I have tried:

  • sudo apt-get-update
  • Running a media cleaner WP plugin. The site was transferred over by copying from another site, so I thought that deleting old images might help, but it didn’t.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi there @umpire,

It is possible that the PHP max_memory is set too high or the MySQL settings might need to be tweaked.

I could suggest the following things:

  • First check your PHP and/or Apache error logs for some more information on what might be causing the problem
  • Add a SWAP file so that you could have some extra buffer in case that your memory runs out
  • Reduce the PHP memory to 128M if possible so that it does not use to much RAM for a single process
  • Tweak your MySQL settings

Let me know how it goes.
Regards,
Bobby

by Brian Boucheron
One way to guard against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file to an Ubuntu 20.04 server.

Hello, @umpire

I will definatelly recommend you to add a swap file if you haven’t done this yet and also use the MySQL tuner script and see if the MySQL configuration needs an improvement.

You can also create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps!
Regards,
Alex