Connect to MySQL on Vagrant instance with Sequel Pro

前端 未结 10 1559
囚心锁ツ
囚心锁ツ 2021-02-02 18:03

I am running Laravel on Vagrant and I am trying to connect Sequel Pro.

I have just started using Vagrant, I have followed a few tutorials on connecting to Sequel Pro how

相关标签:
10条回答
  • 2021-02-02 18:50

    The issue is that MySQL as you have it setup in my.cnf now can only connect via localhost within the Vagrant server:

    bind-address            = 127.0.0.1 
    

    To enable networking in MySQL, you should change that setting in my.cnf to:

    bind-address            = 0.0.0.0
    

    And then restart the MySQL service. Unsure of how that would happen in Vagrant, but in Ubuntu you would enter a command like this:

    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.

    As explained in the official MySQL documentation:

    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.

    • If the address is ::, the server accepts TCP/IP connections on all server host IPv4 and IPv6 interfaces. Use this address to permit both IPv4 and IPv6 connections on all server interfaces.

    • If the address is an IPv4-mapped address, the server accepts TCP/IP connections for that address, in either IPv4 or IPv6 format. 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.

    • 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.

    That said, exposing MySQL—or any database server—to the world is not advisable. 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. Details on all of the different connection types are shown on the official Sequel Pro site here. But this screenshot sums it up nicely.

    Basically you just set your localhost/127.0.0.1 MySQL info as you normally would. But you also add the SSH info you would use to SSH into your server. And Sequel Pro will use that SSH connection to tunnel in & connect to MySQL seamlessly. This might be the better way to handle instead of dealing with MySQL networking & user permission issues.

    enter image description here

    For SSH tunneling in Sequel Pro you just need to do the following:

    • Name: The name you want for the connection.
    • MySQL Host: The IP address of the MySQL host which should be localhost or 127.0.0.1
    • Username: MySQL database username.
    • Password: The password connected to that MySQL database username.
    • Database: Optional (database you want to connect to)
    • Port: Default is 3306 so only change this if you definitely have to set to anything else.

    Now here you set the SSH settings for your Vagrant install:

    • SSH Host: The hostname or IP address of your Vagrant machine.
    • SSH User: The SSH username to that Vagrant machine.
    • SSH Password: The password connected to that SSH user.
    • SSH Port: Default is 22 so only change this if you definitely have to set to anything else.
    0 讨论(0)
  • 2021-02-02 18:52

    Try https://github.com/AlexDisler/mysql-vagrant, it lets you connect without an ssh tunnel (check out install.sh for the specific settings).

    0 讨论(0)
  • 2021-02-02 18:52

    All the above answers didn't work for me until I have tried this:

    • Connect to your vagrant instance using vagrant ssh
    • When just type passwd to set a new password. Use password vagrant for consistency.

    It will connect easily after that steps taken.

    Thanks to @hugo at How do I Sequel Pro with PuPHPet?

    0 讨论(0)
  • 2021-02-02 18:52

    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.

    If you do that and then follow the rest of the original answer, you should be able to connect via sequel pro

    0 讨论(0)
  • 2021-02-02 18:53

    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

    After that restart 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).

    sequel pro settings

    Note there are security issues here since it's all pretty open but for dev work it's fine.

    0 讨论(0)
  • 2021-02-02 18:55

    this is my configration:

    Vagrant machine default ssh user and ssh password all are vagrant.

    0 讨论(0)
提交回复
热议问题