Skip to content

How to change a MySQL configs on DigitalOcean

Pre-requisite: You need to ssh into the server. To connect, please see here

This is the technical roadmap to change a variable:

  1. Freeze the platform, so no-one can do anything while you are changing the variable:
bash
php artisan down
  1. Backup the current configuration file:
bash
sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
  1. Open the configuration file with vim:
bash
sudo vim /etc/mysql/my.cnf

If this file does not work, please make the changes on:

bash
sudo vim /etc/my.cnf
  1. Make the desired changes.

  2. Restart the MySQL server:

bash
sudo service mysql restart
  1. Unfreeze the platform:
bash
php artisan up
  1. Remove the backup file if it’s no longer necessary:
bash
sudo rm /etc/mysql/my.cnf.backup

Specific case for putting max_connections variable

Normally, you cannot have a value of more than 214 on max_connections variable. To be able to increase that variable, you need to execute the steps below:

  1. Open the security file for *nix system with vim:
bash
sudo vim /etc/security/limits.conf
  1. Put these two lines at the bottom:
text
*   hard    nofile  8192
*   soft    nofile  4096
  1. Open the configuration file with vim:
bash
sudo vim /etc/mysql/my.cnf
  1. Put these two lines below [mysqld]:
text
open-files-limit=4096
max_connections=750
  1. Restart the MySQL server:
bash
sudo service mysql restart
  1. If that does not work, you might need to restart the server for security variables to take effect (and then restart the mysql again):
bash
sudo reboot
sudo service mysql restart