[mysql] Clean up partially-created database files when mysql_install_db fails.

Tom Lane tgl at fedoraproject.org
Fri Sep 7 15:17:31 UTC 2012


commit e9d2b26f88f7eea93d8a74d747cc70ffc7ace7e1
Author: Tom Lane <tgl at redhat.com>
Date:   Fri Sep 7 11:17:05 2012 -0400

    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 files changed, 8 insertions(+), 1 deletions(-)
---
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


More information about the scm-commits mailing list