如何连接到VirtualBox Vagrant内的Mysql服务器?

我用Vagrant装了一个新的VirtualBox机器,在那个VM里面安装了Mysql Server。 如何连接到vm外的服务器? 我已经转发Vagrantfile的端口3306,但是当我尝试连接到mysql服务器时,它的resposts错误:'读取初始通信数据包'

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 

确保MySQL绑定到0.0.0.0而不是127.0.0.1,否则将无法从机器外部访问

你可以通过编辑你的my.conf文件并寻找bind-address项来保证这一点 – 你希望它看起来像bind-address = 0.0.0.0 。 然后保存这个并重新启动mysql:

 sudo service mysql restart 

如果你正在生产服务器上这样做,你想知道的安全隐患,在这里讨论: https : //serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to -0-0-0-0

ssh vagrant@127.0.0.1 -p 2222 (密码stream浪者)login到你的机器,

然后: sudo nano /etc/mysql/my.cnf ,注释掉以下几行#

 #skip-external-locking #bind-address 

保存并退出

那么: sudo service mysql restart

然后你可以通过SSH连接到你的MySQL服务器。

对于任何想用mysql工作台或续集的人来说,这些都是input:

 Mysql Host: 192.168.56.101 (or ip that you choose for it) username: root (or mysql username u created) password: **** (your mysql password) database: optional port: optional (unless you chose another port, defaults to 3306) ssh host: 192.168.56.101 (or ip that you choose for this vm, like above) ssh user: vagrant (vagrants default username) ssh password: vagrant (vagrants default password) ssh port: optional (unless you chose another) 

来源: https : //coderwall.com/p/yzwqvg

我最近遇到这个问题。 我用PuPHPet来生成一个configuration。

要通过SSH连接到MySQL,“vagrant”密码不适用于我,而不得不通过SSH密钥文件进行身份validation。

连接MySQL Workbench

连接方法

通过SSH的标准TCP / IP

SSH

 Hostname: 127.0.0.1:2222 (forwarded SSH port) Username: vagrant Password: (do not use) SSH Key File: C:\vagrantpath\puphpet\files\dot\ssh\insecure_private_key (Locate your insercure_private_key) 

MySQL的

 Server Port: 3306 username: (root, or username) password: (password) 

testing连接。

那么,既然没有给出的答复帮助了我,我不得不看更多,并在本文中find解决scheme。

简而言之,答案如下:

使用MySQL Workbench连接到MySQL

 Connection Method: Standard TCP/IP over SSH SSH Hostname: <Local VM IP Address (set in PuPHPet)> SSH Username: vagrant (the default username) SSH Password: vagrant (the default password) MySQL Hostname: 127.0.0.1 MySQL Server Port: 3306 Username: root Password: <MySQL Root Password (set in PuPHPet)> 

使用给定的方法,我能够使用MySQL Workbench从主机Ubuntu机器上连接到mysql数据库,并使用Valentina Studio。

这对我工作: 连接到在stream浪汉的MySQL

 username: vagrant password: vagrant sudo apt-get update sudo apt-get install build-essential zlib1g-dev git-core sqlite3 libsqlite3-dev sudo aptitude install mysql-server mysql-client sudo nano /etc/mysql/my.cnf change: bind-address = 0.0.0.0 mysql -u root -p use mysql GRANT ALL ON *.* to root@'33.33.33.1' IDENTIFIED BY 'jarvis'; FLUSH PRIVILEGES; exit sudo /etc/init.d/mysql restart # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.box_url = "http://files.vagrantup.com/lucid32.box" #config.vm.boot_mode = :gui # Assign this VM to a host-only network IP, allowing you to access it # via the IP. Host-only networks can talk to the host machine as well as # any other machines on the same network, but cannot be accessed (through this # network interface) by any external networks. # config.vm.network :hostonly, "192.168.33.10" # Assign this VM to a bridged network, allowing you to connect directly to a # network using the host's network device. This makes the VM appear as another # physical device on your network. # config.vm.network :bridged # Forward a port from the guest to the host, which allows for outside # computers to access the VM, whereas host only networking does not. # config.vm.forward_port 80, 8080 config.vm.forward_port 3306, 3306 config.vm.network :hostonly, "33.33.33.10" end 

删除known_hosts文件(/Users/…/.ssh/known_hosts)为我工作。

希望这会有所帮助。