I have started laravel recently, and I get the error
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select count(*) as aggregate from `users` where `email` = ***)
on a clean freshly made project when I try to register with the default auth system. php artisan migrate
works well, and I can connect to the database through mysql workbrench with the same credentials as in the .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=udemy-cms
DB_USERNAME=root
DB_PASSWORD=
I am using homestead with laravel, and mysql workbrench. I tried php artisan config:clear
but did
not help.
database.php is default
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'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'),
]) : [],
Thanks in advance for any help.
First I would suggest to check if you can actually connect to your mysql using your current credentials. You should be able to connect to it in your command line like this:
mysql -uroot -p
This basically tries to connect to mysql using root as a user with no password. If that does not work your user does not exist or your password is wrong.
If it works you should run following, to see if your database udemy-cms actually exists:
show databases;
If it does not show your database you need to create it.
CREATE DATABASE udemy-cms;
It is also possible that your user does not have enough permissions, in this case you need to grant your current user enough permissions.