Last Updated: September 09, 2019
·
63.46K
· jamesgecko

Connect to MySQL in Vagrant with Sequel Pro

This is quick and dirty; don't use with anything that isn't a development VM.

First, vagrant ssh and add a user that can connect from anywhere.

mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION; FLUSH PRIVILEGES;"

Next, find the address MySQL is bound to.

cat /etc/mysql/my.cnf | grep bind-address

This is the MySQL host you'll be connecting to.

We'll be using the SSH connection tab in Sequel Pro. The username is root. By default, no password is required.

Vagrant's default SSH settings are as follows:
* SSH Host: 127.0.0.1
* SSH User: vagrant
* SSH Key: ~/.vagrant.d/insecureprivatekey
* SSH Port: 2222

Enjoy!

15 Responses
Add your response

Thanks for the assist.

over 1 year ago ·

One thing to note, is that this causes issues with multiple vagrant servers. I would set it up this way:
SSH Host: VAGRANTBOXIP
SSH User: vagrant
SSH Key: ~/.vagrant.d/insecureprivatekey
SSH Port: leave blank

Otherwise if you have multiple vagrant servers, you will have to delete the line from your known_hosts file every time you switch servers.

over 1 year ago ·

Just a quick addition for anyone stumbling upon this - you might need to add -proot (assuming your password is root) into that command if mysql won't allow you to connect:

mysql -u root -proot -e "GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION; FLUSH PRIVILEGES;"

over 1 year ago ·

Just tried this with the lastest Sequel Pro. I connect, but then after about 10~20 seconds, connection dies. anyone else seeing errors?

over 1 year ago ·

The following worked well for me: https://gist.github.com/johnantoni/3288329

over 1 year ago ·

Another option is to connect to MySQL using SSH. The default Vagrant SSH username and password are: vagrant/vagrant.

Sequel Pro has the option to connect via SSH.

over 1 year ago ·

Thanks!

over 1 year ago ·

Thanks, it’s very helpful ! Works like a charm.

over 1 year ago ·

Very handy, thanks!

over 1 year ago ·

Has anyone had any issues with this configuration using Vagrant 1.5.x (I'm using 1.5.3)? I was able to connect using Sequel Pro without any issues using the above suggestions before upgrading, but now, I can't connect. I using the latest VirtualBox v4.3.10.

SSH connection failed!
The SSH Tunnel has unexpectedly closed.

over 1 year ago ·

Awesome stuff, thanks.

over 1 year ago ·

@kayzee - I upgraded my vagrant and started having issues the same as you. In case it helps anyone else I sshed into my vagrant box and manually set the password for the vagrant user by

passwd vagrant

Then it worked with the same connection as what @reinink states at the top of the comments.

over 1 year ago ·

Very helpful, thank you

over 1 year ago ·

I just upgraded to 1.7.4 and this no longer works. Sequel Pro now prompts for the vagrant password when it tries to connect. The password should just be 'vagrant' but it's definitely not as user friendly as it used to be.

over 1 year ago ·

For those using VVV / WordPress:

Connect with SSH, set Username and Password to those in your wp-config.php

I also had to set a password for vagrant user:

vagrant ssh
sudo passwd vagrant

Was prompted to put that in on connecting with Sequel Pro

over 1 year ago ·