diskimage-builder/elements/mysql/first-boot.d/50-mysql
Clint Byrum 05ccb5eab5 Clean up the MySQL element to make it suitable for generic use.
Change-Id: Ib3e384d6fb48e6df53a0897bcc48bbb46995a824
2012-12-18 09:41:26 -08:00

30 lines
938 B
Bash
Executable File

#!/bin/bash
set -uex
CNF=/etc/mysql/my.cnf
cp -f $(dirname $0)/my.cnf $CNF
sed -i "s/^bind-address=.*/bind-address=0.0.0.0/" $CNF
D_SYS_MAINT="--defaults-file=/etc/mysql/debian.cnf"
# 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
# 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
service mysql start