Question

out of memory error. error establishing database conncetion

Posted November 25, 2020 317 views
UbuntuWordPress

hello. every time I log into One of my website it keeps happening. Error establishing database connection, and I get out of memory kill process mysqld in ssh console. sometimes it fixes itself in 15-20 seconds. But sometimes I have to turn off and turn on again droplet to solve it. Is that happening cause it needs to increase memory limit? I want to know how to diagnose exactly why this keep happening and then find the method how to fix it. thanks

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
1 answer

Hey, @levanmirvelashvili

You can first check the MySQL configuration and make sure that the values and memory assigned to the buffer_pool is not higher that it should be as this is likely to cause issues like this.

What you can also do is to use the MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

  • SSH to your Droplet
  • Download the script:
wget http://mysqltuner.pl/ -O mysqltuner.pl
  • Then execute it:
perl mysqltuner.pl

The script would run multiple checks against your MySQL instance, all checks done by MySQLTuner are documented here.

Also as stated in the official documentation, it is still extremely important for you to fully understand each change you make to a MySQL database server. If you don’t understand portions of the script’s output, or if you don’t understand the recommendations, you should consult a knowledgeable DBA or system administrator that you trust.

As a good practice make sure to always test your changes on staging environments before implementing them on your production database.

On the same note, if you want to have a worry-free MySQL hosting and focus on your application, I would recommend trying out the DigitalOcean Managed Databases:

https://www.digitalocean.com/products/managed-databases-mysql/

This was mini tutorial was posted from bobbyiliev in this question in our community: https://www.digitalocean.com/community/questions/how-to-tweak-mysql-mariadb-configuration-for-increased-performance-and-stability

Hope that this helps!
Regards,
Alex

  • Hi, @alexdo

    I had exactly same experience as the OP described.

    I’ve been running a lot of WP websites on DO and this never happened before.
    I created a new account for the client and created WP Droplet with the new droplet creation wizard that you get when you first log in to account (as opposed to before where I would go to Droplet > Marketplace and chose WP from there) and with fresh theme install I used 10s of times before I keep getting MySQL timeouts when I perform random actions in WP Admin.

    Is this maybe caused with the new wizard?
    Would hate to have to hire a DB person to T/S this when it was never an issue before on DA. Easier just swapping providers.

    These are MySQL tuner results which don’t really say much https://imgur.com/a/HihC0GA
    Please let us know if there is a solution to this?
    Thanks

    • Hello,

      I’ve just tested this on a fresh droplet and so far everything seems fine with it.
      You can also examine the MySQL error log as this will help you to indicate any errors.

      Also please check for any killed processes in /var/log/messages

      You can do this via these commands:

      grep -i kill /var/log/messages
      

      and

      grep -i oom /var/log/messages
      

      Feel free to share the output of the commands here and we can check them further.

      Hope that this helps!
      Regards,
      Alex