Unfortunately there is no process or command what can shrink or purge ibdata1 file. There is only one way is to drop all you DB’s with InnoDB engine and restore them from the backup.
Depends on the size of you database you need plan your downtime for the service.
First, add following to the MySQL config file (/etc/my.cnf or other location depends on your installation):
This change will allow to store all indexes separately per table.
Then follow next steps what I applied at many my servers successfully and without issues:
- Backup all you InnoDB engine DB’s with mysqldump command:
mysqldump -u super_user -p db_name > db_name.sql
Note: you can avoid backing up mysql and performance_schema databases.
Note: this command will help you to find databases with InnoDB engine:
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = ‘innodb’;
- After the backup process is completed you will need to drop all InnoDB databases ( I sum you backed up all of them):
mysql -u super_user -p -e “drop database db_name;”
- Stop mysql/mariadb service:
systemctl stop mariadb
systemctl stop mysqld
service mariadb stop
service mysqld stop
- Delete all following files from the MySQL db location, usually /var/lib/mysql:
rm -rf ibdata1
rm -rf ib_logfile0
rm -rf ib_logfile1
- Start mysql/mariadb service:
systemctl start mariadb
systemctl start mysqld
service mariadb start
service mysqld start
Note: at this stage ibdata1 and ib_log files will be recreated
- Create empty databases where you will restore from the backup:
mysql -u super_user -p -e “create database db_name;”
- Restore all backed up databases back:
mysql -u super_user -p dbname < db_name.sql