MySQL on Ubuntu Keeps Crashing : There are so many internet commonly wordpress users who face this problem where the MYSQL on their server getting crashed frequently. I personally faced this problem in my WordPress blog that running VPS few months ago. Because wordpress need atleast 512 MB RAM (1 GB RECOMMENDED) for the smoother running. MySQL crashing problem occurs mainly due to lack of memory (RAM) space. i.e. when your RAM usage hits the maximum. This problem can be solved by restarting the MYSQL service with the command sudo service mysql restart and this is not a feasible solution because we need execute this command each time when the MYSQL crashes. Try restarting the server itself if the above command does not solve the problem. Another way to solve the issue is adding more RAM to the servers by contacting the hosting provider which is an expensive solution.
MySQL on Ubuntu Keeps Crashing
But we can solve this issue to a certain extent using two methods that described below these are the perfect solution unless you are ready to upgrade your server memory which is expensive. So i am sharing those methods for crashing of MySQL frequently.
Method 1 : Increase innodb pool size
InnoDB buffer pool is the memory space that holds many in-memory data structures of InnoDB, buffers, caches, indexes and even row-data. innodb_buffer_pool_size is the MySQL configuration parameter that specifies the amount of memory allocated to the InnoDB buffer pool by MySQL. Increasing innodb pool size can solve the issue of crashing MySQL
## Edit /etc/my.cnf, and add the following line under the [mysqld] heading. [mysqld] innodb_buffer_pool_size=64M
$ service mysql restart
Method 2 : Add Swap Space
Step 1: Check for existing swap space available in your system
Run the following commnad to display the list of swap space present in your system
sudo swapon -s
If you have an empty list, proceed the following steps.
Step 2: Check for available memory space(of hard disk) available in your system
Run the command df to list the availability of memory space in your system.
df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda 20907056 1437188 18421292 8% / udev 121588 4 121584 1% /dev
It is always to better to add swap space equal to twice the RAM or at least equal to the RAM present in your system.
Step 3: Creating the swap file
Create the swap file with the following commands
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k sudo mkswap /swapfile
- swapfile is the name of the swap file
- bs represents the block size in bytes
- count=512k will add 512MB of swap space
Now you will get the following display message.
Setting up swapspace version 1, size = 262140 KiB no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb
Step 4: Activating the swap space
Run the following command so that the swap space is available to use for the operating system.
sudo swapon /swapfile
Step 5: Verify the availability of swap space
Run the command sudo swapon -s to list the swap spaces added in your system. You will get message something like below.
swapon -s Filename Type Size Used Priority /swapfile file 262140 0 -1
Step 6: Making the swap file permanent
The swap space added will be retained only till the machine reboots. To make the swap permanent open the file fstab using the command sudo nano /etc/fstab and add the following to a new line
/swapfile none swap sw 0 0
Step 7: Setting up the permission for the swap file
Run the following command to make the swap file readable and writable only by the root user of the system.
sudo chown root:root /swapfile sudo chmod 0600 /swapfile