Bash scripts if/else statements, task failed

In my opinion all works correctly, but i can’t complete task.

#!/bin/bash

set -x
#set -o errexit # # let script exit if a command fails
set -o nounset # let script exit if an unsed variable is used

DB_NAME=“kodekloud_db01”
DB_USER=“kodekloud_roy”
DB_USER_PASS=“asdfgdsd”
IMPORT_PASS=“/opt/db_backups/db.sql”
DUMP_PATH=“/opt/db_backups/$DB_NAME.sql”
#Check if database exist.
if [ -d /var/lib/mysql/$DB_NAME ] ; then
echo “Database already exists”
else
mysql -e “CREATE DATABASE $DB_NAME”
echo “Database ‘$DB_NAME’ has been created”
fi

#Create user with password
mysql -e “CREATE OR REPLACE USER ‘$DB_USER’ IDENTIFIED BY ‘$DB_USER_PASS’ ;”
mysql -e “GRANT ALL PRIVILEGES ON $DB_NAME.* to ‘$DB_USER’ ;”
mysql -e “flush privileges;”

#check if the database is empty
if mysql $DB_NAME -e “SHOW TABLES” | grep -q “.”; then
echo “database is not empty”
else
#import database dump
mysql $DB_NAME < $IMPORT_PASS
echo “imported database dump into $DB_NAME database.”
fi

mysqldump $DB_NAME > $DUMP_PATH

you didn’t specified the wildcard host when creating the user

what if the user kodekloud roy already exists? it gives error