Vagrant port forwarding for Mysql

前端 未结 3 843
渐次进展
渐次进展 2020-12-15 23:34

I am trying to setup port forwarding in Vagrantfile to connect to guest mysqld from host system, but get reading initial communication packet error. Host: Yosem

3条回答
  •  無奈伤痛
    2020-12-16 00:26

    was finally able to make it work -

    edit the /etc/mysql/my.cnf file and make sure, either

    • you have bind-address = 0.0.0.0
    • or you comment the line #bind-address ...

    You may need to add it to the mysqld section of the my.cnf file:

    [mysqld]
    bind-address = 0.0.0.0
    

    make sure to restart your mysql server after the change

    $ sudo service mysql restart
    

    Then you can connect from your host - so I first had an error like

    $ 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
    

    so I came back to the guest and did

    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)
    

    Then I had no issue to connect from the host machine

    $ 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)
    

提交回复
热议问题