How to Fix Frequent MySQL Crashes on Alibaba Cloud

timg

If you’re using a low-spec Alibaba Cloud server, the system may frequently stop MySQL as traffic increases. Besides upgrading system resources such as memory and storage, you can try the following steps:

1. Reduce the InnoDB buffer pool size
Find the MySQL configuration file, usually at /etc/mysql/my.cnf or /etc/my.cnf. Edit the file and add or update the following line:

innodb_buffer_pool_size = 64M

2. Add a SWAP partition
Alibaba Cloud servers don’t come with a SWAP partition by default, but you can create one yourself. Run the following commands in order in the shell:

dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile

Explanation: First, create a 1024M swap file made up of 1024 blocks of 1M each. Then format the file as swap space and enable it.

3. Enable SWAP at startup
Add the following line to /etc/fstab so the SWAP space you just created is enabled automatically after a reboot:

/swapfile swap swap defauluts 0 0

4. Restart MySQL
Use the following command to restart MySQL:

service mysql restart

After completing the steps above, check whether MySQL still stops frequently. If it does, try limiting the number of MySQL connections as described below.

Additional steps
You can also limit the number of MySQL connections. Open the MySQL configuration file again and add or update the following line:

max_connections = 100

If you’ve tried all of these steps and are still having trouble, consider upgrading your server’s memory, CPU, or other resources, or using Alibaba Cloud’s database service. :)

References
[1] https://my.oschina.net/cenchy/blog/740259
[2] https://oldtang.com/138.html

Add a Comment

Your email address will not be published. Required fields are marked *