title: bash check mysql connect
body: <p>I'm writing a bash script to do some operations against a database on my debian squeeze Server.</p>
  
  <p>I have noticed that if I enter a wrong password for root, the prompt will be closed and I won't be asked to try again... that's not very convenient!</p>
  
  <p>So I was trying to create a loop that attempts to connect to MYSQL and save the password for later if successful.</p>
  
  <p>I tried this, but it doesn't work.
  Instead, I receive this error:</p>
  
  <blockquote>
    <p>ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)</p>
  </blockquote>
  
  <pre><code>read -s -p "Enter MYSQL root password: " mysqlRootPassword
  
  while [[ -n `mysql -u root -p$mysqlRootPassword` ]]; do
         read -p "Can't connect, please retry: " mysqlRootPassword
  done
  </code></pre>
  
  <p>I am not very experienced in bash scripting, any help would be awesome!</p>