Reputation: 299
I recently installed VM and Vagrant to work with my Laravel projects. So I'm new to this. I dont have MySQL installed on my main machine. I tried to Vagrant up
and then ssh [email protected] -p 2222
. Everything is fine and dandy uptil this point. I want to access MySQL and cant get access. This is what ive done:
mysql -u root -p (password "") -h localhost
mysql -u root -p (password "root") -h localhost
mysql -u root -h localhost
And even all of those without -h localhost
. I havent set up MySQL before so keep in mind, ive never made an account to even access MySQL.
Ive searched around and ive found this:
Go to:
sudo vi /etc/mysql/my.cnf
And comment out: skip-external-locking
and change this: bind-address: 0.0.0.0
.
I then went back and restarted MySQL using sudo service mysql restart
and tried those commands again...still no access.
Btw the error im getting is: 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 was logged in!!! but i dont think i was supposed to do it that way. and that password provided by that file is probably a hash of something.
Im stuck. I dont know what to do from here!
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)
Upvotes: 7
Views: 8560
Reputation: 1608
I run this
homestead up
homestead ssh
mysql -u homestead -psecret
for laravel 5.2 and default .env values
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Upvotes: -1
Reputation: 146
Considering you're working on a local vagrant server, I think it's okay to give this a try to rule out any other possible problems. Definitely don't do this on a production server, and ensure that your Vagrant machine is only accessible by 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
Upvotes: 3