Question

MySql crashes on Ubuntu 16.04 using WordPress

Hello,

I have an issue right now with my Server Ubuntu 16.04 and I was hoping someone could help or guide me to the solution. I recently installed Wordpress and it worked fine for 3 days but now it is displaying the following error: “Error establishing a database connection”. It always crashes for a couple of seconds and then it works again, but this keeps happening all the time. So I collected the logs for Mysql and I found this:

<^>2018-01-26T04:01:17.405635Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12 2018-01-26T04:01:17.405656Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool 2018-01-26T04:01:17.405666Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error 2018-01-26T04:01:17.405676Z 0 [ERROR] Plugin ‘InnoDB’ init function returned error. 2018-01-26T04:01:17.405683Z 0 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed. 2018-01-26T04:01:17.405691Z 0 [ERROR] Failed to initialize builtin plugins. 2018-01-26T04:01:17.405697Z 0 [ERROR] Aborting

2018-01-26T04:01:17.405712Z 0 [Note] Binlog end 2018-01-26T04:01:17.408006Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2018-01-26T04:01:47.308940Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2018-01-26T04:01:47.308976Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) 2018-01-26T04:01:47.467060Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_def aults_for_timestamp server option (see documentation for more details). 2018-01-26T04:01:47.468608Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-0ubuntu0.16.04.1) starting as process 5600 … 2018-01-26T04:01:47.472435Z 0 [Note] InnoDB: PUNCH HOLE support available 2018-01-26T04:01:47.472454Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-01-26T04:01:47.472458Z 0 [Note] InnoDB: Uses event mutexes 2018-01-26T04:01:47.472462Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2018-01-26T04:01:47.472478Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8 2018-01-26T04:01:47.472481Z 0 [Note] InnoDB: Using Linux native AIO 2018-01-26T04:01:47.472701Z 0 [Note] InnoDB: Number of pools: 1 2018-01-26T04:01:47.472810Z 0 [Note] InnoDB: Using CPU crc32 instructions 2018-01-26T04:01:47.474205Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2018-01-26T04:01:47.482501Z 0 [Note] InnoDB: Completed initialization of buffer pool 2018-01-26T04:01:47.484835Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2018-01-26T04:01:47.504123Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2018-01-26T04:01:47.506227Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 28060943 2018-01-26T04:01:47.506240Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 28060952 2018-01-26T04:01:47.506244Z 0 [Note] InnoDB: Database was not shutdown normally! 2018-01-26T04:01:47.506248Z 0 [Note] InnoDB: Starting crash recovery. 2018-01-26T04:01:47.689508Z 0 [Note] InnoDB: Removed temporary tablespace data file: “ibtmp1” 2018-01-26T04:01:47.689526Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2018-01-26T04:01:47.689556Z 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait … 2018-01-26T04:01:47.725880Z 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB. 2018-01-26T04:01:47.726525Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active . 2018-01-26T04:01:47.726535Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2018-01-26T04:01:47.726671Z 0 [Note] InnoDB: Waiting for purge to start 2018-01-26T04:01:47.776850Z 0 [Note] InnoDB: 5.7.21 started; log sequence number 28060952 2018-01-26T04:01:47.777089Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2018-01-26T04:01:47.778297Z 0 [Note] Plugin ‘FEDERATED’ is disabled. 2018-01-26T04:01:47.787146Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180126 4:01:47 2018-01-26T04:01:47.787636Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context i s not usable without certificate and private key 2018-01-26T04:01:47.825642Z 0 [Note] Event Scheduler: Loaded 0 events 2018-01-26T04:01:47.825743Z 0 [Note] /usr/sbin/mysqld: ready for connections. Version: ‘5.7.21-0ubuntu0.16.04.1’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 (Ubuntu) 2018-01-26T04:01:48.311112Z 2 [Note] Access denied for user ‘root’@‘localhost’ (using password: NO)<^>

I’m definitely not a server expert, but I will appreciate if someone could tell what this means, and what solutions should I try

Thank you!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted Answer

As it says: “Cannot allocate memory for the buffer pool”. You ran out of memory.

alexdo
Site Moderator
Site Moderator badge
October 20, 2020

Hello,

You can check if the MySQL innodb_buffer_pool_size is not set to a value that exceeds the available RAM on your droplet.

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

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

alexdo
Site Moderator
Site Moderator badge
October 19, 2020

Hello,

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel