markdown 从主机连接Vagrant VM中的MySQL数据库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 从主机连接Vagrant VM中的MySQL数据库相关的知识,希望对你有一定的参考价值。

# Connecting to Vagrant VM MySQL database from host

This gist shows how to connect to your vagrant MySQL database from 
the host machine.

### Change Address Binding from MySQL

* Connect to vagrant using `vagrant ssh`
* Edit file `/etc/mysql/my.cnf`:
  * Change parameter `bind-address` to `0.0.0.0` to allow all incoming connection attempts
  * __NOTE__: Do not allow this in production
* Change privileges of the MySQL user to allow connection attempts from any host:
  * On host connect as root user using `mysql -uroot -proot`
  * `mysql>` appears
  * Insert `GRANT ALL PRIVILEGES ON *.* TO username@'%' IDENTIFIED BY "password";`
  * `username@'%'` grants access from all hosts

## Connect to DB by using MySQL Workbench

* Add a new connection with the following parameters
  * Connection Method: `Standard TCP/IP over SSH`
  * SSH Hostname: `127.0.0.1:2222` if your VM is listening on port `2222` (showing on VM startup)
  * SSH username: `vagrant` or your vagrant user
    * SSH Key File: Use the path showing at `IdentityFile` when you type `vagrant ssh-config` on your vagrant root folder (in case vagrant uses `SSH auth method: private key`. Showing on VM startup)
    * SSH Password: In case you use `SSH auth method: password` on your VM
  * MySQL Hostname: 127.0.0.1
  * MySQL Server Port: 3306
  * Username: Your MySQL username

以上是关于markdown 从主机连接Vagrant VM中的MySQL数据库的主要内容,如果未能解决你的问题,请参考以下文章

5运行多个vagrant主机

如何从另一个 virtualbox 来宾访问 vagrant 来宾?

如何从Vagrant box运行ganache-cli?

如何从 vagrant virtualbox 机器连接主机 PostgreSQL

从hometead vagrant连接主机的SQL Server 2017

在现有的vagrant box上添加端口转发