Homestead: ERROR 1045 (28000): Access denied for user 'homestead'@'localhost' (using password: YES)

Created on 23 Jul 2018  ·  4Comments  ·  Source: laravel/homestead

Up until today my Homestead was running quite alright.

This morning I had a homestead database open in Sequel Pro. While it was trying to read it, I tried to cancel it, and quitted the app.

I tried to reconnect to MySQL via Sequel Pro afterwards, it didn't work.
I tried provisioning vagrant reload --provision. I got an error at the end of this:
https://gist.github.com/gormus/f6dc6ba5311367b76fd6f89fe2b4cba5

When I SSH'ed into the box and run mysql, I got another error:

vagrant@homestead:~$ mysql
ERROR 1045 (28000): Access denied for user 'homestead'@'localhost' (using password: YES)

Meanwhile MySQL service is active and running:

vagrant@homestead:~$ sudo service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-07-23 20:11:37 UTC; 28min ago
  Process: 1154 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
  Process: 663 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1156 (mysqld)
    Tasks: 28 (limit: 3531)
   CGroup: /system.slice/mysql.service
           └─1156 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Jul 23 20:11:32 homestead systemd[1]: Starting MySQL Community Server...
Jul 23 20:11:37 homestead systemd[1]: Started MySQL Community Server.

As last resort I wanted destroy the vagrant box and re-create it. However I got hit by another error (see below).

Right now, I cannot access to databases. I cannot even create backups of them. And not sure how to resolve this.

Somehow the database got corrupted, when I interrupted it while it was reading from it. Now not sure how to proceed. Suggestions?

Versions

  • Vagrant 2.1.2
  • Provider: Virtualbox 5.2.12 r122591 (Qt5.6.3)
  • Homestead: Vagrant 2.1.2 (Run homestead --version to show the version.)

Host operating system

macOS Hig Sierra (10.13.6)

Vagrant destroy & up output

~/Homestead $ vagrant destroy -f
==> homestead-7: Running triggers before destroy ...
==> homestead-7: Running trigger...
==> homestead-7: Backing up mysql database drupal8...
    homestead-7: Running: inline script
    homestead-7: mysqldump: Got error: 1045: Access denied for user 'homestead'@'localhost' (using password: YES) when trying to connect
==> homestead-7: Trigger run failed
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Most helpful comment

I had similar problem also. I noticed that I do not have .my.cnf file in /root/.my.cnf path and /home/vagrant/.my.cnf. I run vagrant reload --provision and files was recreated. You can also just create this files manually with content

[client]
user = homestead
password = secret
host = localhost

All 4 comments

Even the root access is denied:

vagrant@homestead:~/mysql_backup$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Looks like something has changed the mysql password for homestead user.

If you care about backing up your databases:

  • Let this be the last time you put something IN a VM you don't have a backup of
  • run vagrant up
  • follow normal "resetting mysql root password" procedures
  • Dump your databases
  • Continue with the next section to manually destroy the VM and recreate

If you don't care about your DBs:

  • Open virtual box
  • Stop homestead VM
  • remove Homestead VM (Select "delete all files")
  • cd to where you run vagrant commands from
  • rm -rf .vagrant
  • vagrant up

I had similar problem also. I noticed that I do not have .my.cnf file in /root/.my.cnf path and /home/vagrant/.my.cnf. I run vagrant reload --provision and files was recreated. You can also just create this files manually with content

[client]
user = homestead
password = secret
host = localhost

Thanks @kierzniak. But that's not the case for me. I have both .my.cnf files in place.
And provisioning didn't help on that issue either.
I've been pulled away from this task, so, I'm yet to try @svpernova09 's recommendation. Hopefully soon...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mtpultz picture mtpultz  ·  4Comments

pluxain picture pluxain  ·  3Comments

leandroruel picture leandroruel  ·  4Comments

it-can picture it-can  ·  3Comments

cschoeni picture cschoeni  ·  4Comments