title: Granting access to root from localhost
body: <p>I'm following this <a href="http://www.thisprogrammingthing.com/2013/getting-started-with-vagrant/" rel="nofollow">link</a> on how to set up a LAMP stack with Vagrant. </p>
  
  <p>Because that link uses wordpress, I had to modify the code a bit. However I'm getting an error: </p>
  
  <p><code>access denied for user 'root'@'localhost' (using password: YES)</code></p>
  
  <p>This error occurs when I'm trying to create user, create database, etc in my shell file.. I've searched this error online and it suggests that I need to grant access to root from localhost. I'm not sure how to do this in my <code>provisions.sh</code>. Can anyone provide some advice?</p>
  
  <p>Here is my shell file:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  #set variable
  ROOTPASS=default_root_pw
  
  # setting answers to questions during install
  sudo debconf-set-selections &lt;&lt;&lt; 'mysql-server-5.5 mysql-server/root_password password $ROOTPASS'
  sudo debconf-set-selections &lt;&lt;&lt; 'mysql-server-5.5 mysql-server/root_password_again password $ROOTPASS'
  
  sudo apt-get update
  sudo apt-get -y install mysql-server-5.5 php5-mysql apache2 php5
  
  # check if databasesetup file exists, if it doesn't, it means this is first time 
  # and we should create user"
  
  if [ ! -f /var/log/databasesetup ];
  then
      echo "CREATE USER 'user'@'localhost' IDENTIFIED BY 'user_password'" | mysql -uroot -p$ROOTPASS
      echo "CREATE DATABASE my_database" | mysql -uroot -p$ROOTPASS
      echo "GRANT ALL ON my_database.* TO 'user'@'localhost'" | mysql -uroot -p$ROOTPASS
      echo "flush privileges" | mysql -uroot -p$ROOTPASS
  
      # create databasesetup file to prevent recreating users in future ..."
      touch /var/log/databasesetup
  
      # checking if initial.sql exists to restore it into VM database...
  
      if [ -f /vagrant/data/initial.sql ];
      then
          mysql -uroot -p$ROOTPASS my_database &lt; /vagrant/data/initial.sql
      fi
  fi
  
  if [ ! -h /var/www ]; 
  then 
      rm -rf /var/www sudo
      ln -s /vagrant/public /var/www
  
      service apache2 restart
  fi
  </code></pre>