From cae704db91b2b46bd397a6d9fef43cc935f83362 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 7 Sep 2012 11:17:05 -0400 Subject: [PATCH] Clean up partially-created database files when mysql_install_db fails. This allows a subsequent attempt to succeed. Per discussion of bug #835131. --- mysqld-prepare-db-dir | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mysqld-prepare-db-dir b/mysqld-prepare-db-dir index 72badd7..78c0bd7 100644 --- a/mysqld-prepare-db-dir +++ b/mysqld-prepare-db-dir @@ -45,10 +45,17 @@ if [ ! -d "$datadir/mysql" ] ; then echo "Initializing MySQL database" /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql ret=$? - chown -R mysql:mysql "$datadir" if [ $ret -ne 0 ] ; then + echo "Initialization of MySQL database failed." >&2 + echo "Perhaps /etc/my.cnf is misconfigured." >&2 + # Clean up any partially-created database files + if [ ! -e "$datadir/mysql/user.frm" ] ; then + rm -rf "$datadir"/* + fi exit $ret fi + # In case we're running as root, make sure files are owned properly + chown -R mysql:mysql "$datadir" fi exit 0