0

I'm trying to run:

php artisan migrate:install

But I'm getting:

[PDOException]                                                                         
  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) 

This is my .env file:

APP_ENV=local
APP_DEBUG=true
APP_KEY=XXXX
APP_URL=http://localhost

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=

But I can access the database with MySQL Workbench:

hostname: 127.0.0.1
port: 3306
username: root
password:

How can I fix this?

Filipe Ferminiano
  • 8,373
  • 25
  • 104
  • 174
  • You need to check your database credentials, like the error message says. You probably aren't allowed to connect as root without a password. (If you are, that's bad, and you should change that.) – elixenide Oct 16 '16 at 18:39
  • Yes, I can do that. Because I did on mysql workbench, as I mentioned in the question – Filipe Ferminiano Oct 16 '16 at 18:41
  • Well, there's a difference there. MySQL Workbench is connecting and being seen as `'root'@'127.0.0.1'`. Your script is connecting and being seen as `'root'@'localhost'`. Those *resolve* to the same machine, but they are not the same in terms of MySQL `GRANT`s. Again, check your permissions. And again, you should not allow connections as root from *any* IP/host without a password, and preferably not even with one. – elixenide Oct 16 '16 at 18:46
  • Also be aware that there is a difference between *no* password and an empty password. IIRC, MySQL Workbench treats an empty password field as "no password", but Laravel treats it as "the password is the empty string." Those are not the same, and they require different `GRANT` statements. – elixenide Oct 16 '16 at 18:51
  • Forget that you even have a root acct when you test your app. No good reason to use it and it exposes you to hacks. Make sure you have a strong root password. Create users and grant appropriately. – Drew Oct 16 '16 at 20:25

0 Answers0