Connecting to Vagrant [PuPHPet] MySql from host

database

Connecting to Vagrant [PuPHPet] MySql from host

Probably here with – I can’t connect to mysql on vagrant machine Yup I have been there

If you are php developer and are using vagrant you would want to use mysql tool to access the vagrant mysql server.

Here is the step by step procedure.

I will assume the PuPHPet configuration
First, get the user which can connect from any host

Log into your vagrant

vagrant ssh

Then open the mysql configuration file

vi /etc/mysql/my.cnf

And update the bind-address part to be 0.0.0.0. This will allow address to be used from any host.
If you want to specifically access from some host only, then put IP over there.

Then being in your vagrant machine run

mysql -uroot -p123

This will be depending on if you have provided a password for root the default on puPHPet would ask password so you would have a password

After this allow root user to access everything from everywhere.. or you can create another user and grant that

mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123';
mysql > FLUSH PRIVILEGES;

Then to make the sql pickup the changes made so far

sudo service mysql restart

Then being on your host machine open your sequel pro – if you are on mac.. or other clients you would use for mysql.

Mysql Host: 127.0.0.1
Mysql user: root
Mysql Password: 123

SSH Host: 127.0.0.1
SSH Username: vagrant – this is the default one
SSH key -> point the key in puphpet/files/dot/ssh/id_rsa
SSH Port: 2222 – this is also the default ssh port forwarding, if you change this change it here too..

See how to Setting up vegrant machine from scratch here

AbstractSureFireMojo Class Missing Maven Surefire

Spring Data error: getOutputStream() has already been called for this response

No Persistence provider for EntityManager named Hibernate error

Java Tomcat error: can not access a member of class with modifiers

Add scrollbar to mysql result in terminal

You asked to pull from the remote but did not specify the branch github error

2 Comments
  1. John van Terheijden

    Why don’t you just ssh tunnel into the vm using the private key (puphpet/files/dot/ssh/id_rsa)? Then you don’t need to change or configurate anything – good practice for your prod servers too as it will increase security. Most GUIs will let you do his or you can use command line (http://stackoverflow.com/questions/18373366/mysql-connection-over-ssh-tunnel-how-to-specify-other-mysql-server)

    1. gullele

      Thank you very much John, that is a good advice actually. I will change that, test it and will post another blog on that showing how I have done it using the my ssh config and stuff..

      Again, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*