MySQL logs are files that record various information about your database activity, such as sessions, queries, errors, and performance. While these logs can be useful for debugging or monitoring purposes, they can also consume a lot of disk space over time and affect your website performance.
If you want to disable MySQL logging completely, you will need to edit the configuration file to comment out the lines that enable the different types of logs. Then, you will need to restart the MySQL service to apply the changes.
Here are the steps to follow:
- Log in to your server as the
root
user via SSH.
ssh root@your-server-ip
- Locate and edit the MySQL configuration file: The location of the MySQL configuration file varies depending on your Ubuntu version:
- Ubuntu 20.04 and older: Edit the
/etc/mysql/my.cnf
file. - Ubuntu 22.04 to Ubuntu 24.04: Edit the
/etc/mysql/mariadb.conf.d/50-server.cnf
file. - Ubuntu 22.04 and later: In addition to the above file, you may need to edit
/etc/mysql/conf.d/runcloud.cnf
to add specific settings.
- Ubuntu 20.04 and older: Edit the
To open the appropriate configuration file with a text editor, such as nano
, use the following command (adjust the path according to your Ubuntu version):
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Note: If you can’t find the configuration file in the specified directory, check the /etc/mysql/
directory for a my.cnf
file.
- Comment out logging directives: Locate the following lines in the configuration file. These lines may start with
general_log
,slow_query_log
, orlog_bin
. Add a#
symbol at the beginning of each line to comment them out, effectively disabling them.
If you are editing the /etc/mysql/conf.d/runcloud.cnf
file (for Ubuntu 22.04 and later), ensure that the skip-log-bin
directive is present under the [mysqld]
section. If it is not there, add it manually:
[mysqld]
...
skip-log-bin
- Save and Exit: To save and exit the file in
nano
, press:Ctrl + O
to write the changes.Enter
to confirm.Ctrl + X
to exit the editor.
- Restart the MySQL Service: Restart the MySQL service to apply the changes:
service mysql restart
That’s it! You have successfully disabled MySQL logging on your server. You can also delete the existing log files from the /var/log/mysql/
directory if you don’t need them anymore.