Laravel database acces denied root

i’m tryin to conect my laravel project for the first time with my database mysql but is getting impossible. I have ubuntu 20. Whenever I try to migrate (php artisan migrate) i keep getting this:

Illuminate\Database\QueryException     SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')    at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671     667|         // If an exception occurs when attempting to run a query, we'll format the error     668|         // message to include the bindings with SQL, which will make this exception a     669|         // lot more helpful to the developer instead of just the database's errors.     670|         catch (Exception $e) {   > 671|             throw new QueryException(     672|                 $query, $this->prepareBindings($bindings), $e     673|             );     674|         }     675|         +34 vendor frames    35  artisan:37       Illuminate\Foundation\Console\Kernel::handle() 

I tried everything… my .ENV file i believe is correct:


i have a user "root" and pass "1234". In console it works just fine -> sudo mysql -u root -p (and then 1234)… I also have created the database laravel1 in phpmyadmin, so that’s ok… help

Add Comment
1 Answer(s)

sudo mysql -u root -p here is issue it should work like mysql -u root -p(without sudo)

you can’t access your database without root access to solve this i use

  • Step 1 sudo mysql -u root -p —- login with this then run cmd

  • Step 2 > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234'; —- here u can change your password anything u want


it should work

Answered on September 1, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.