Sometimes, when you run out of space, you can see that there are lots of files like
in your mysql directory (usually /var/lib/mysql). How can you delete these logs without harming your server?
These are mysql binary log files. These are files that contain information about data modifications, that were made by the MySQL server. The log consists of a set of binary log files, plus an index file, so you cannot just use rm to delete them all. In 99.9% cases these files are useless and your server can work without them.
Fortunately, there is a simple MySQL command that will allow you to clean them. Let me share it.
First of all, login as root.
mysql -uroot -p
Then, use the following command:
PURGE BINARY LOGS BEFORE NOW();
The command above will delete all these old files, and only the latest one will be left. In 5 seconds about 25 Gb on my server were available again.