Skip to content

Instantly share code, notes, and snippets.

@rwohleb
Created October 14, 2014 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rwohleb/0d590e2a3cefcfa0e09f to your computer and use it in GitHub Desktop.
Save rwohleb/0d590e2a3cefcfa0e09f to your computer and use it in GitHub Desktop.
Upgrade MySQL to innodb_file_per_table [FOUND, UNTESTED]
#!/bin/bash -x
if test "$USER" != "root" ; then
echo "Must be root ..."
exit 1
fi
mysql_dba=root
mysql_pass=your_mysql_dba_password
mkdir /var/lib/mysql.bak
cd /var/lib/mysql.bak
service mysql stop && cp -ra /var/lib/mysql mysqldata && service mysql start
mysqldump -u$mysql_dba -p$mysql_pass --routines --events --flush-privileges --all-databases > all-db.sql
mysql -u$mysql_dba -p$mysql_pass -e "SELECT DISTINCT CONCAT ('DROP DATABASE ',TABLE_SCHEMA,' ;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA <> 'mysql' AND TABLE_SCHEMA <> 'information_schema';" | tail -n+2 > drop.sql
cat drop.sql
mysql -u$mysql_dba -p$mysql_pass < drop.sql
echo "SELECT table_name, table_schema, engine FROM information_schema.tables WHERE engine = 'InnoDB';" > innotables.sql
mysql -u$mysql_dba -p < innotables.sql
service mysql stop
rm /var/lib/mysql/ibdata1 && rm /var/lib/mysql/ib_logfile0 && rm /var/lib/mysql/ib_logfile1
cp -p /etc/mysql/my.cnf /etc/mysql/my.cnf.
date +%Y.%m.%d.%H.%M.%S
sed -e 's/([mysqld])/\1\ninnodb_file_per_table = 1\ninnodb_file_format = barracuda /' /etc/mysql/my.cnf > /tmp/my.cnf
mv /tmp/my.cnf /etc/mysql/my.cnf
service mysql start
mysql -u$mysql_dba -p$mysql_pass < all-db.sql
mysql_upgrade -u$mysql_dba -p$mysql_pass --force
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment