gpt4 book ai didi

mysql - Mysql 的 Vagrant 端口转发

转载 作者:IT老高 更新时间:2023-10-29 00:10:37 32 4
gpt4 key购买 nike

我试图在 Vagrantfile 中设置端口转发以从主机系统连接到 guest mysqld,但是出现reading initial communication packet 错误。主持人:Yosemite,嘉宾:Trusty, vagrant 1.7.4

Vagrant 文件(主机):

config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 3309

my.ini( guest ):

bind-address            = 127.0.0.1

8080 转发就像一个魅力。

mysql -h127.0.0.1 -uroot -p 来自 guest 也可以。

mysql -h127.0.0.1 -P 3309 -uroot -p 来自主机的 reading initial communication packet 错误。

当我从主机远程登录时,连接立即关闭:

$ telnet localhost 3309
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

当我从主机 ssh 到 vagrant box 时,端口转发工作:

$ssh vagrant@127.0.0.1 -p 2222 -L3308:localhost:3306 

然后我可以毫无问题地从主机 mysql -h127.0.0.1 -P3308 -uroot -p 进行连接,我将其用作临时解决方法。

最佳答案

终于能够让它工作了-

编辑/etc/mysql/my.cnf 文件并确保,要么

  • 你有 bind-address = 0.0.0.0
  • 或者您注释行 #bind-address ...

您可能需要将它添加到 my.cnf 文件的 mysqld 部分:

[mysqld]
bind-address = 0.0.0.0

确保在更改后重新启动您的 mysql 服务器

$ sudo service mysql restart

然后你可以从你的主机连接 - 所以我首先遇到了这样的错误

$ mysql -h127.0.0.1 -P 3309 -uroot -p
Enter password:
ERROR 1130 (HY000): Host '172.16.42.2' is not allowed to connect to this MySQL server

所以我回到客人那里做了

vagrant@precise64:~$ mysql -h127.0.0.1 -uroot -p
...
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.42.2' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

然后我从主机连接就没有问题了

$ mysql -h127.0.0.1 -P 3309 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.44-0ubuntu0.12.04.1 (Ubuntu)

关于mysql - Mysql 的 Vagrant 端口转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146223/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com