Search code examples
laravelmariadbcredentials

Laravel 5.4 access denied for user root@localhost on migrate


I have a stange one with Laravel. I have a bad habit of creating projects on virtual box with laravel project for testing. (debian last stable currently 9.1, nginx, php7.1, MariaDB).

Before you tell me to go read another post somewhere, please read everything, I mays have missed the post but I tried quite à lot I tried most of the solution that may have worked for others, but they don't in my case (thanks).

I tried different thing and always end breaking everything and doing hover (that's normal...).

I have already tried a number of installation and never had any problem with

php artisan migrate

That is until today. I prepared my migrations files and tried the migrate and I got this message :

[Illuminate\Database\QueryException]
  SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: sele
  ct * from information_schema.tables where table_schema = test and table_nam
  e = migrations)

And this one:

[PDOException]
  SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

I did everything as always, I checked my credentials that are in the .env file and tested them. No problem there.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=Password2

The database does exist, can't be wrong with this name :

SHOW DATABASEs;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

When looking for code error 1698 in MariaDB, they tell me that this code appear when it's trying to connect without password.

So my question is why is it doing this? I tried with a new project, just installed and doing the artisan command line, it changes nothing.

I would like to avoid doing a fresh os install.

Thanks in advance for your help and sorry for my poor english.


Solution

  • So I solved my problem... It seems that I need to create a new database account to write in the database and can't use root...

    I tested it with another virtual machine and if I create a new account it works as it should...

    Seems that the issue is with MariaDB... I can connect with or without password to root even after mysql_secure_installation command... I will work on this...

    Thanks a lot.