Vagrant SSH - Setup and Connect to MySQL

I recently installed VM and Vagrant to work with my Laravel projects. Therefore, I am new to this. I do not have MySQL on my main machine. I tried Vagrant up and then ssh vagrant@127.0.0.1 -p 2222 . Everything is in order, and the dandy raised this moment. I want to access MySQL and not access. This is what has been done:

 mysql -u root -p (password "") -h localhost mysql -u root -p (password "root") -h localhost mysql -u root -h localhost 

And even everything without -h localhost . I have not configured MySQL before, so keep in mind ive never made an account even to access MySQL.

I searched around and I found this:

Switch to:

 sudo vi /etc/mysql/my.cnf 

And comment out: skip-external-locking and change this: bind-address: 0.0.0.0 .

Then I came back and restarted MySQL with sudo service mysql restart and tried these commands again ... still no access.

Btw error im get: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

However, there was something that I found interesting ... I went to cd /etc/mysql and I found a file named: debian.cnf and it had a username and password and I tried that username and password and I logged in !!! but I don’t think I should have done it that way. and this password provided by this file is probably a hash of something.

I am stuck. I do not know what to do next!

Update I forgot to add: if I just provide mysql , I get this error ERROR 1045 (28000): Access denied for user 'vagrant'@'localhost' (using password: NO)

+6
source share
3 answers

I had the same problem but after

 vagrant up && vagrant ssh 

I did

 sudo service mysql restart 

and I could connect to mysql console without errors.

+4
source

Given that you are working on a local roaming server, I think that everything is in order to try to eliminate any other possible problems. Definitely do not do this on the production server and make sure that your vagrant machine is available only to you.

 # fill in the blanks for root password, db name, username (local), and password mysql -u root -p"rootpassword" -e "CREATE DATABASE db_name; CREATE USER 'local'@'localhost' IDENTIFIED BY 'password'; CREATE USER 'local'@'%' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'local'@'localhost'; GRANT ALL PRIVILEGES ON * . * TO 'local'@'%'; FLUSH PRIVILEGES;" # change bind address to allow connections from anywhere sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf # restart the sql service sudo service mysql restart 
+2
source

I run this

 homestead up homestead ssh mysql -u homestead -psecret 

for laravel 5.2 and default values ​​.env

 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret 
-1
source

Source: https://habr.com/ru/post/972541/


All Articles