title: Unable to login after installing MySQL database using bash script
body: <p>I have connected to a remote CentOS machine in SSH and ran the below script to install a MySQL database there:</p>
  
  <pre><code># install and start mysql
  yum -y install mysql-server
  service mysqld start
  
  # setup some random passwords
  USER_PASS=`openssl rand -base64 8`
  ROOT_PASS=`openssl rand -base64 12`
  
  # create an SQL file to be executed for 
  # changing root password, setting up new user, create new database etc.
  
  echo "UPDATE mysql.user SET Password=PASSWORD('$ROOT_PASS') WHERE User='root';" &gt; /tmp/init.sql
  echo "DELETE FROM mysql.user WHERE User='';" &gt;&gt; /tmp/init.sql
  echo "DROP DATABASE test;"  &gt;&gt; /tmp/init.sql
  echo "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';" &gt;&gt; /tmp/init.sql
  echo "CREATE DATABASE testdb;" &gt;&gt; /tmp/init.sql
  echo "CREATE USER 'testusr'@'127.0.0.1' IDENTIFIED BY '$USER_PASS';"  &gt;&gt; /tmp/init.sql
  echo "CREATE USER 'testusr'@localhost IDENTIFIED BY '$USER_PASS';" &gt;&gt; /tmp/init.sql
  echo "GRANT ALL PRIVILEGES ON testdb.* TO 'testusr'@'127.0.0.1';" &gt;&gt; /tmp/init.sql
  echo "GRANT ALL PRIVILEGES ON testdb.* TO 'testusr'@'localhost';" &gt;&gt; /tmp/init.sql
  echo "flush privileges;" &gt;&gt; /tmp/init.sql
  
  # execute the SQL file from root user
  cat /tmp/init.sql | mysql -u root
  </code></pre>
  
  <p>After this, whenever I try to login locally using the <code>testusr</code> user I created above, I get Access Denied message. However the root login (using the newly set root password) seems to work. What am I missing here?</p>