skip to Main Content

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


  1. 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:

    DB_PASSWORD="Your-password-with-###-here"
    

    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.

    Login or Signup to reply.
  2. 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.

    DB_PASSWORD="Use only the laravel allowed db password allowed characters"
    

    I think it should work for all lavavel lovers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search