Search code examples
mysqlvagrantremote-connection

Cannot access vagrant MySQL database from outside (only when vagrant ssh'd into the box w/Scotchbox)


I am running Vagrant & Virtual Box - I have a PHP/MySQL setup within my Vagrantfile when I vagrant ssh via the terminal I can access my database directly without any issue using the default root user (password is 'root')

My Vagrant IP is 192.168.33.1 and I have added this to my hosts file to map to dev.myworkspace.com

When I run the following command to access the mysql -h dev.myworkspace.com -u root -p & enter the correct password (root) it returns the following error:

ERROR 1045 (28000): Access denied for user 'root'@'192.168.33.1' (using password: YES)

I have tried adding bind-address = 0.0.0.0 to the my.cnf file within the vagrant box but when I restart mysql it hangs.

Can anyone explain what I am doing wrong? I just want to be able to connect to my vagrant MySQL database albeit from outside vagrant ssh (so need to allow external connections)

NOTE - the root user has been setup as the follows: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'


Solution

  • I looks that the permission for user root are only set to localhost

    Try this to queries. If the second gives no result try the update and **flush*

    SHOW GRANTS FOR  'root'@'localhost';
    SHOW GRANTS FOR  'root'@'%';
    
    UPDATE mysql.user
    SET Host='%' WHERE Host='localhost' AND User='root';
    
    FLUSH PRIVILEGES;