yzwqvg
Last Updated: November 01, 2016
·
43.3K
· 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

1031
1e58f8f9625d015ed97b506bbfbf6d52

Thanks for the assist.

over 1 year ago ·
1786
89b61c1bdf3c32ea49a332258c40ebd8

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 ·
3417

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 ·
4152
1e58f8f9625d015ed97b506bbfbf6d52

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 ·
5803

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

over 1 year ago ·
6307

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 ·
6420

Thanks!

over 1 year ago ·
11569
877ababe8a8c890b5c03f4521a04b77d

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

over 1 year ago ·
12729
75e96f9c04c31a340e8c3ce2b6c4f72d

Very handy, thanks!

over 1 year ago ·
14119
5b98f358f202d29a66bc72186aa375d1

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 ·
14162
7cd12f2ba5090ca96dc1d71152ee0e61

Awesome stuff, thanks.

over 1 year ago ·
15459
47badcdbed5437dc04a18de70da4464d

@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 ·
18133
None

Very helpful, thank you

over 1 year ago ·
22534
Ig normal

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 ·
28282

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

2 months ago ·