Quantcast
Viewing latest article 1
Browse Latest Browse All 11

Answer by Pierre-Alexis de Solminihac for How to shrink/purge ibdata1 file in MySQL

Quickly scripted the accepted answer's procedure in bash:

#!/usr/bin/env bashdbs=$(mysql -BNe 'show databases' | grep -vE '^mysql$|^(performance|information)_schema$')mysqldump --events --triggers --databases $dbs > alldatabases.sql && \    echo "$dbs" | while read -r db; do        mysqladmin drop "$db"    done && \    mysql -e 'SET GLOBAL innodb_fast_shutdown = 0'&& \    /etc/init.d/mysql stop && \    rm -f /var/lib/mysql/ib{data1,_logfile*} && \    /etc/init.d/mysql start && \    mysql < alldatabases.sql

Save as purge_binlogs.sh and run as root.

Excludes mysql, information_schema, performance_schema (and binlog directory).

Assumes you have administrator credendials in /root/.my.cnf and that your database lives in default /var/lib/mysql directory.

You can also purge binary logs after running this script to regain more disk space with:

PURGE BINARY LOGS BEFORE CURRENT_TIMESTAMP;

Viewing latest article 1
Browse Latest Browse All 11

Trending Articles