MySQL Data Directory Management

See Database Management Systems.

The mysql/data folder should be cleaned up by an IT Professional in the following scenarios:


Consider the following before beginning the cleanup process. These considerations are for MySQL versions 5.5 and 5.6, or MariaDB 10.5.

Cleanup Suggestions

Any database with "backup" in the name can be moved out of the data folder and into a different folder. If cleaning up the data folder for a MariaDB upgrade, files can be moved to the mysql/backups folder. The backups folder should also be routinely cleaned up.

Note: Sort the data folder by Date Modified to which databases have been used recently.

Cleanup Process

Before beginning the cleanup process, verify the database(s) are in MyISAM format and not in InnoDB before moving them.

  1. Stop MySQL service.
  2. Move databases from the data folder to a different directory.
    • If .PID file exists, the MySQL service may still be running. Verify it has stopped then disable the service until cleanup is complete.
  3. Clean up *.err files.
    • Move the entire file into the new directory.
    • There may be multiple files. The filename that contains the server name is the most current file.
  4. If replication/binary log files are present, continue to Replication Cleanup below.
  5. Restart the MySQL service.

Replication Cleanup Process

Begin the Cleanup Process above, then follow the steps before for Replication Cleanup.

Start MySQL service, then in the MySQL Command Line, run the following command: PURGE BINARY LOGS BEFORE NOW() - INTERVAL 10 DAY;

Note: If this does not work, stop the MySQL service and ensure Replication has caught up on all servers, then move the files into a backup folder. Do not delete the most recent binlog file. Instead, copy the files from this directory into .\mysql\backups\YYYYMMDD (use the current date).