init: use the -e mysql flag to specify the query

This commit is contained in:
Sameer Naik 2014-09-24 23:13:50 +05:30
parent 1d4f53fdc8
commit b6aa5bf526

View File

@ -290,10 +290,10 @@ if [ "${DB_HOST}" == "localhost" ]; then
sleep 1
done
if ! echo "USE ${DB_NAME}" | mysql -uroot ${DB_PASS:+-p$DB_PASS} >/dev/null 2>&1; then
if ! mysql -uroot ${DB_PASS:+-p$DB_PASS} -e "USE ${DB_NAME};" >/dev/null 2>&1; then
DB_INIT="yes"
echo "CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;" | mysql -uroot ${DB_PASS:+-p$DB_PASS}
echo "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DB_NAME}\`.* TO 'root'@'localhost';" | mysql -uroot ${DB_PASS:+-p$DB_PASS}
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';"
fi
fi