Search code examples
mysqllaravelvagrantlaravel-forge

how to Connect to Remote DB from vagrant box


I have a local vagrant box I want to connect this box to the database server located on the forge server

My .env file on vagrant

DB_HOST= remote_server_ip
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=password

and on my /etc/mysql/my.cnf file
bind-address = *

however when I try to open the site I receive
SQLSTATE[HY000] [2002] Connection timed out


Solution

  • Go to your db server and execute below statement.

    grant select,update,delete,insert,drop on your_db.* to forge@'your_ip' identified by 'your_password';
    

    If you want to provide all rights and globally then below command-

    grant all privileges on *.* to forge@'%' identified by 'your_password';
    

    If still you are not able to connect remotely then check your iptables setting, you can either enable port 3306 from there or completely disable iptables service by below command as per your requirement-

    $ service iptables stop