Connect to MySQL on Vagrant instance with Sequel P

2019-03-13 05:46发布

I am running Laravel on Vagrant and I am trying to connect Sequel Pro.

I have just started using Vagrant, I have followed a few tutorials on connecting to Sequel Pro however they were all unsuccessful.

Here is my Vagrant file:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure('2') do |config|
config.vm.hostname = 'laravel'
config.vm.boot_timeout = 3600
config.vm.box = 'debian-73-i386-virtualbox-puppet'
config.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/debian-73-i386-virtualbox-puppet.box'

config.vm.network :forwarded_port, guest: 8000, host: 8000
config.vm.network :forwarded_port, guest: 8500, host: 8500

config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', '1536']
end

config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'puppet/'
puppet.manifest_file  = 'init.pp'
puppet.module_path    = 'puppet/modules/'
# puppet.options      = '--verbose --debug'
end

end

From my.cnf:

bind-address            = 127.0.0.1 

Here is my /etc/hosts

127.0.0.1       localhost
127.0.1.1       laravel
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

EDIT: changed bind address to 0.0.0.0 still does not work In Sequel Pro I have

MySQL Host: 0.0.0.0
username: root
Password: (mysql password)
SSH Host 0.0.0.0
SSH User: vagrant
SSH Password: vagrant

EDIT: Here is my vagrant hosts file - etc/hosts

This is my hosts file

127.0.0.1       localhost
127.0.1.1       laravel
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

9条回答
戒情不戒烟
2楼-- · 2019-03-13 06:37

All you need to do is edit the bind address located here:

$ sudo nano /etc/mysql/my.cnf

Find the bind_address setting which will be set to 127.0.0.0 and change it to 0.0.0.0

After that restart mySQL:

$ sudo service mysql restart

The final step is just updating permissions:

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

Then connect as you normally would (changing port to what ever you set in your vagrant file).

sequel pro settings

Note there are security issues here since it's all pretty open but for dev work it's fine.

查看更多
放荡不羁爱自由
3楼-- · 2019-03-13 06:40

For me, the vital part was using 0.0.0.0 as MySQL host instead of 127.0.0.1. Everything else is business as usual (using SSH). This works for me:

enter image description here

查看更多
萌系小妹纸
4楼-- · 2019-03-13 06:42

Your connection to your Vagrant box has to be made via SSH. So if you have connected before, and have made any major changes to your Vagrant box (such as a destroy/rebuild), you may have a new private key and need to refresh your IP address record in ~/.ssh/known_hosts. To do that, open the file in vim and just delete the line that starts with your vagrant box IP address.

查看更多
登录 后发表回答