Search code examples
mysqldatabaselaravel-6.2

SQLSTATE[HY000] [1045] Access denied for user 'wymtavvh_admin'@'localhost' (using password: YES)


I am using laravel on a live shared hosting and I am getting the error above despite using the right database connection credentials. I have edited the .env and the database.php files and added the necessary credentils. My problem is that the same credentials are working on a raw php file that I have written to test but not on laravel. the laravel project works correctly though on localhost

here is a sample of the .env file code

      DB_CONNECTION=mysql
      DB_HOST=127.0.0.1
      DB_PORT=3306
      DB_DATABASE=wymtav_food
      DB_USERNAME=wymtav_admin
      DB_PASSWORD=PasswordNce
      BROADCAST_DRIVER=log
      CACHE_DRIVER=file
      QUEUE_CONNECTION=sync
      SESSION_DRIVER=file
      SESSION_LIFETIME=120

and here is a snippet of the edited database.php file

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'wymtav_food'),
        'username' => env('DB_USERNAME', 'wymtav_admin'),
        'password' => env('DB_PASSWORD', 'PasswordNce'),
        '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'),
        ]) : [],
    ],

Note that on local environment, the database port was 3309 and I have changed it to 3306 as per the production environment port. What could I be doing wrong?


Solution

  • As it turned out my host had set the database password and username to be the same as the ones for accessing the cpanel. No other user created could do read or write the db directly unless logged into the phpmyadmin. Therefore anyone who experiences this problem especially in directadmin, can try changing the credentials to the ones for login into directadmin