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.