5

I get this error in the browser on my test Laravel project:

Illuminate\Database\QueryException
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
(SQL: select count(*) as aggregate from `users` where `email` = test@test.com)

I have found similar problems in Stack Overflow and other sites, but all the solutions given never worked for me.

Another similar error code refers to MySQL, but mine is about Laravel. Not MySQL.
I use Ubuntu 18.04 (Bionic Beaver), Laravel 6, LAMP, my database is MySQL, the server is served by Apache 2.4, not Homebrew or PHP localhost.

----------(test project context)

I'm following a tutorial and I successfully added the LOGIN and REGISTER button. Now when I try to register a new user, I got two permission issues which I was able to solve with sudo chmod, but I have been stuck on this third problem for five hours now. I'm going to reinstall everything if I don't get this right by today.

In my understanding PHP ARTISAN UI:AUTH takes care of all the code and you only need to PHP ARTISAN MIGRATE after creating the authorization UI which I already did. I can actually see the tables MIGRATE created in database in the MYSQL terminal.

----------(/test project context)

Solutions I've tried:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1 or 127.0.0.11 or localhost
DB_PORT=3306 or 33060
DB_DATABASE=test
DB_USERNAME=root or I_created_a_new_user_with_all_privileges
DB_PASSWORD=password

I've tried matching my database configuration in the app\config\database.php file in Laravel.

I already sudo chmod 777 /var/www/html/blog out of desperation.

I tried a bunch of clears in the terminal.

php artisan config:cache
php artisan config:clear
php artisan cache:clear

This is app\config\database.php file:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),  <--- NEVER TRIED THIS PART THOUGH, idk what to put
            'host' => env('DB_HOST', '127.0.0.1'), <---- tried all
            'port' => env('DB_PORT', '3306'),      <---- tried 33060
            'database' => env('DB_DATABASE', 'forge'), <--- tried 'test' as my DB
            'username' => env('DB_USERNAME', 'forge'), <--- tried 'root' or 'nico'
            'password' => env('DB_PASSWORD', ''), <--- 'password'
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',      <--- tried 'utf8'
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

I already checked the owners of the file and the programs. It's either root or www-data and made sure that Apache2 is ran by root or www-data either or both. I used ps aux | grep apache.

I never had this problem in Windows 10 WAMP stack. I'm at my wits end.

I recreated the project from scratch, but I still get the same error.

This article solved it: #1698 - Access denied for user 'root'@'localhost' mysql -5.7 and ubuntu-16.04

Step 1. `sudo mysql -u root -p`

Step 2. `USE mysql;`

Step 3. `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';`

Here 'admin' is your new password, but you can change it.

Step 4. Exit Thanks. You are done.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shu Pesmerga
  • 155
  • 1
  • 1
  • 15

5 Answers5

2

Try this soution !

    sudo mysql -u root -p
    > use mysql;
    > select user,host,plugin from mysql.user;
    > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    > flush privileges;
1

May be you should change the file .env

DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

with values as in config/database.php

sergmoro1
  • 11
  • 2
0

Try double-quote your password ( "password"). Sometimes it works.

0

I use double quotes on my password and it works for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zakhele
  • 97
  • 1
  • 2
0

The solution I found was to install xampp and use mariadb from there, it works perfectly for me.

use el traductor para escribir lo de arriba xd

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '23 at 15:38
  • Please write your answer in English, as Stack Overflow is an [English-only site](https://meta.stackoverflow.com/a/297680). – cursorrux Jan 10 '23 at 07:59