init: replace -uroot with -u ${DB_USER} in the mysql commands

This commit is contained in:
Sameer Naik 2014-09-24 23:19:03 +05:30
parent b6aa5bf526
commit 78078b08a4

View File

@ -280,7 +280,7 @@ if [ "${DB_HOST}" == "localhost" ]; then
# wait for mysql server to start (max 120 seconds)
timeout=120
while ! mysqladmin -uroot ${DB_PASS:+-p$DB_PASS} status >/dev/null 2>&1
while ! mysqladmin -u ${DB_USER} ${DB_PASS:+-p $DB_PASS} status >/dev/null 2>&1
do
timeout=$(expr $timeout - 1)
if [ $timeout -eq 0 ]; then
@ -290,10 +290,10 @@ if [ "${DB_HOST}" == "localhost" ]; then
sleep 1
done
if ! mysql -uroot ${DB_PASS:+-p$DB_PASS} -e "USE ${DB_NAME};" >/dev/null 2>&1; then
if ! mysql -u ${DB_USER} ${DB_PASS:+-p $DB_PASS} -e "USE ${DB_NAME};" >/dev/null 2>&1; then
DB_INIT="yes"
mysql -uroot ${DB_PASS:+-p$DB_PASS} -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;"
mysql -uroot ${DB_PASS:+-p$DB_PASS} -e "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DB_NAME}\`.* TO 'root'@'localhost';"
mysql -u ${DB_USER} ${DB_PASS:+-p $DB_PASS} -e "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;"
mysql -u ${DB_USER} ${DB_PASS:+-p $DB_PASS} -e "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DB_NAME}\`.* TO 'root'@'localhost';"
fi
fi