[英]Connect to MySQL on Vagrant instance with Sequel Pro
I am running Laravel on Vagrant and I am trying to connect Sequel Pro. 我在Vagrant上运行Laravel,我正在尝试连接Sequel Pro。
I have just started using Vagrant, I have followed a few tutorials on connecting to Sequel Pro however they were all unsuccessful. 我刚刚开始使用Vagrant,我已经按照一些关于连接到Sequel Pro的教程,但是他们都没有成功。
Here is my Vagrant file: 这是我的Vagrant文件:
# -*- 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
: 来自my.cnf
:
bind-address = 127.0.0.1
Here is my /etc/hosts
这是我的/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 编辑:更改绑定地址为0.0.0.0仍然不起作用在续集专业我有
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 编辑:这是我的vagrant hosts文件 - 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
The issue is that MySQL as you have it setup in my.cnf
now can only connect via localhost
within the Vagrant server: 问题是你在my.cnf
设置的MySQL现在只能通过Vagrant服务器中的localhost
连接:
bind-address = 127.0.0.1
To enable networking in MySQL, you should change that setting in my.cnf
to: 要在MySQL中启用网络,您应该将my.cnf
中的设置更改为:
bind-address = 0.0.0.0
And then restart the MySQL service. 然后重启MySQL服务。 Unsure of how that would happen in Vagrant, but in Ubuntu you would enter a command like this: 不确定在Vagrant中会发生什么,但在Ubuntu中你会输入如下命令:
sudo service mysql restart
You might have to check your MySQL user permissions to ensure that the user within MySQL can actually be used from any IP address—sometimes they are set strictly to localhost
or 127.0.0.1
—as well. 您可能必须检查MySQL用户权限,以确保MySQL中的用户可以从任何IP地址实际使用 - 有时它们严格设置为localhost
或127.0.0.1
。
As explained in the official MySQL documentation : 正如MySQL官方文档中所述 :
The server treats different types of addresses as follows: 服务器处理不同类型的地址,如下所示:
If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces. 如果地址为0.0.0.0,则服务器接受所有服务器主机IPv4接口上的TCP / IP连接。
If the address is ::, the server accepts TCP/IP connections on all server host IPv4 and IPv6 interfaces. 如果地址为::,则服务器接受所有服务器主机IPv4和IPv6接口上的TCP / IP连接。 Use this address to permit both IPv4 and IPv6 connections on all server interfaces. 使用此地址允许所有服务器接口上的IPv4和IPv6连接。
If the address is an IPv4-mapped address, the server accepts TCP/IP connections for that address, in either IPv4 or IPv6 format. 如果地址是IPv4映射地址,则服务器接受IPv4或IPv6格式的该地址的TCP / IP连接。 For example, if the server is bound to ::ffff:127.0.0.1, clients can connect using --host=127.0.0.1 or --host=::ffff:127.0.0.1. 例如,如果服务器绑定到:: ffff:127.0.0.1,则客户端可以使用--host = 127.0.0.1或--host = :: ffff:127.0.0.1进行连接。
If the address is a “regular” IPv4 or IPv6 address (such as 127.0.0.1 or ::1), the server accepts TCP/IP connections only for that IPv4 or IPv6 address. 如果地址是“常规”IPv4或IPv6地址(例如127.0.0.1或:: 1),则服务器仅接受该IPv4或IPv6地址的TCP / IP连接。
That said, exposing MySQL—or any database server—to the world is not advisable. 也就是说,将MySQL或任何数据库服务器暴露给世界是不可取的。 But is acceptable in a case of local development like this. 但在像这样的本地开发的情况下是可以接受的。
So if enabling MySQL networking is not an option, you can also use the built in SSH tunneling capabilities in Sequel Pro to connect to MySQL via SSH. 因此,如果无法启用MySQL网络,您还可以使用Sequel Pro中内置的SSH隧道功能通过SSH连接到MySQL。 Details on all of the different connection types are shown on the official Sequel Pro site here . 有关所有不同连接类型的详细信息,请参见官方Sequel Pro网站 。 But this screenshot sums it up nicely. 但是这个截图总结得很好。
Basically you just set your localhost
/ 127.0.0.1
MySQL info as you normally would. 基本上你只需像往常一样设置localhost
/ 127.0.0.1
MySQL信息。 But you also add the SSH info you would use to SSH into your server. 但是,您还要将用于SSH的SSH信息添加到服务器中。 And Sequel Pro will use that SSH connection to tunnel in & connect to MySQL seamlessly. Sequel Pro将使用该SSH连接进行隧道连接并无缝连接到MySQL。 This might be the better way to handle instead of dealing with MySQL networking & user permission issues. 这可能是更好的处理方式,而不是处理MySQL网络和用户权限问题。
For SSH tunneling in Sequel Pro you just need to do the following: 对于Sequel Pro中的SSH隧道,您只需执行以下操作:
localhost
or 127.0.0.1
MySQL主机:MySQL主机的IP地址,应该是localhost
或127.0.0.1
Now here you set the SSH settings for your Vagrant install: 现在,您可以为Vagrant安装设置SSH设置:
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 找到bind_address设置,该设置将设置为127.0.0.0并将其更改为0.0.0.0
After that restart mySQL: 之后重启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). 然后像往常一样连接(将端口更改为您在vagrant文件中设置的内容)。
Note there are security issues here since it's all pretty open but for dev work it's fine. 请注意,这里存在安全问题,因为它们都非常开放,但对于开发工作来说很好。
尝试https://github.com/AlexDisler/mysql-vagrant ,它允许您在没有ssh隧道的情况下进行连接(请查看install.sh以了解具体设置)。
All the above answers didn't work for me until I have tried this: 在我尝试这个之前,以上所有答案对我都不起作用:
vagrant ssh
使用vagrant ssh
连接到您的vagrant实例 passwd
to set a new password. 只需键入passwd
即可设置新密码。 Use password vagrant
for consistency. 使用密码vagrant
保持一致性。 It will connect easily after that steps taken. 在采取这些步骤后,它将很容易连接。
Thanks to @hugo at How do I Sequel Pro with PuPHPet? 感谢@hugo在我如何使用PuPHPet续集Pro?
The answer about the bind-address is right, however I have found that instead of changing the value to 0.0.0.0, it's better to just edit the my.cnf file and comment out the bind-address altogether. 关于绑定地址的答案是正确的,但是我发现不是将值更改为0.0.0.0,而是编辑my.cnf文件并完全注释掉绑定地址。
If you do that and then follow the rest of the original answer, you should be able to connect via sequel pro 如果您这样做,然后按照原始答案的其余部分,您应该能够通过续集专业版连接
Your connection to your Vagrant box has to be made via SSH. 您与Vagrant盒子的连接必须通过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
. 因此,如果您之前已连接并对Vagrant框进行了任何重大更改(例如销毁/重建),则可能需要新的私钥并需要刷新~/.ssh/known_hosts
IP地址记录。 To do that, open the file in vim and just delete the line that starts with your vagrant box IP address. 为此,请在vim中打开文件,然后删除以您的流浪盒IP地址开头的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.