My env Database is Right but I get this error
SQLSTATE[28000] [1045] Access denied for user ‘elsharkawyazq_climate_app’@’localhost’ (using password: YES)
I’m using laravel 5.8 on PHP 7.3 on my server
I tried other working database didn’t work so env file data is correct but I don’t know why this is happening
My Env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=elsharkawyazq_climate_app
DB_USERNAME=elsharkawyazq_climate_app
DB_PASSWORD=SomePassword!@##@!
My Database
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'elsharkawyazq_climate'),
'username' => env('DB_USERNAME', 'elsharkawyazq_test'),
'password' => env('DB_PASSWORD', 'SomePassword!@##@!'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
i used Xampp on local and everything was fine
2
Answers
The pound sign acts as a comment. You cannot use the pound sign (
#
) as a character in a .env file when it is not escaped. Surround your password with quotes:When I enter the
php artisan tinker
environment, I can load the environment variables from the.env
and when I have a pound sign in a value, it acts as a comment. When put inside quotes it does not.In your .env DB_PASSWORD don’t use any (!) and (#) character. You can use (@) or (%) character in your password. So remove these characters from your DB_password.
I think it should work for all lavavel lovers.