I love how convent PuPHPet makes setting up a Vagrant VM. One of the things that I don't like about it is the fact that you can't access your VMs databases using native tools like MySQL Workbench and Sequel Pro. There are two reasons for this, the first is that by default MySQL is setup to only accept connections from the localhost and the second is that the user created by Puppet can only access the site though local connections or remote connections (it's a slight flaw in the MySQL defaults) but not both.

To fix the problem where MySQL will only accept connections from localhost we need to find the following line in our default.pp:

class { 'mysql::server': config_hash   => { 'root_password' => 'zendpass' } }

And change it to this (whitespace is optional but I added it for readability:

class { 'mysql::server':
  config_hash   => { 
    'root_password' => 'zendpass',
    'bind_address' => '192.168.56.101',
  }
}

This will change the bind_address parameter inside my.ini to the external IP address of the VM.

Next you need to find a section that looks like this:

mysql::db { 'database':
  grant    => [
    'ALL'
  ],
  user     => 'username',
  password => 'password',
  host     => 'localhost',
  charset  => 'utf8',
  require  => Class['mysql::server'],
}

We're going to add the following after this:

database_user { 'username@%':
  password_hash => mysql_password('password')
}

database_grant { 'usernamer@%/database':
  privileges => ['all'] ,
}

This will add an additional permission to the username user so they have access to the database from all hosts.

Now a quick vagrant reload will cause these permissions to be loaded.

Finally, when you're ready to connect you just connect using the IP address of the VM (192.168.56.101 if your using our setup guide to PuPHPet) and the username and password specified.

Like this post? Don't forget to follow us on Twitter and Facebook for updates.