diskimage-builder/elements/mysql/first-boot.d/50-mysql

30 lines
938 B
Plaintext
Raw Normal View History

2012-11-13 00:49:27 +00:00
#!/bin/bash
set -uex
2012-11-13 00:49:27 +00:00
CNF=/etc/mysql/my.cnf
cp -f $(dirname $0)/my.cnf $CNF
sed -i "s/^bind-address=.*/bind-address=0.0.0.0/" $CNF
2012-11-13 00:49:27 +00:00
D_SYS_MAINT="--defaults-file=/etc/mysql/debian.cnf"
2012-11-13 00:49:27 +00:00
# Since we will be clearing out ib_*, make sure there aren't any innodb tables.
if mysqladmin $D_SYS_MAINT ping ; then
innodb_tables=$(mysql $D_SYS_MAINT -N -e "SELECT count(*) FROM information_schema.TABLES WHERE ENGINE LIKE 'InnoDB'")
if [ -n "$innodb_tables" -a $innodb_tables -gt 0 ] ; then
echo Found $innodb_tables InnoDB tables. Any existing data may be lost. ABORT!
exit 1
fi
service mysql stop
fi
2012-11-13 00:49:27 +00:00
# The new my.cnf may not jive with default innodb sizes, so just backup and clear out ib files
if [ -n "$(ls /var/lib/mysql/ib_*)" ] ; then
BACKUP_DIR=/var/backups/mysql-$(date +%Y%m%d%H%M%S)
mkdir -p $BACKUP_DIR
chmod 700 $BACKUP_DIR
mv -f /var/lib/mysql/ib_* $BACKUP_DIR
fi
2012-11-13 00:49:27 +00:00
service mysql start