Mysql command line password with special characters is not working : <p>I've the following bash script to upgrade my database schema. Script reads hostname and database password from command line.</p>

<p>The problem is here that if the password is <strong>alphanumeric</strong> e.g <strong>r00t</strong> then script works. But if password contains special characters e.g <strong>pa**w0rd</strong>, then script does not work and directly exits. Please help me with this. Thanks.</p>

<pre><code>#!/bin/bash

echo "Enter hostname."
read -p "Hostname [localhost]: " DB_HOST
DB_HOST=${DB_HOST:-localhost}

echo "Enter MySQL root password"
DB_PASS=
while [[ $DB_PASS = "" ]]; do
   read -sp "Password: " DB_PASS
done

MYSQL="mysql --force --connect-timeout=90 --host=$DB_HOST -u root --password=${DB_PASS}"

# Apply schema updates. My DBName is "mydb"
# Upgrade schema file is stored in "mysql" folder

$MYSQL mydb -e exit &gt; /dev/null 2&gt;&amp;1 &amp;&amp; $MYSQL mydb &lt; "../mysql/upgrade_schema_v.2.1.sql"
</code></pre>
