skip to Main Content

I have uploaded a Laravel project in my cPanel. It gives the following error

SQLSTATE[HY000] [1044] Access denied for user ‘amartuki_finance’@’localhost’ to database ‘amartuki_finance’

But I have change my .env file’s db name,user and password. Also configure in config/database.php file.

.env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=amartuki_finance
DB_USERNAME=amartuki_finance
DB_PASSWORD=amartuki_finance

config/database.php file

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'amartuki_finance'),
        'username' => env('DB_USERNAME', 'amartuki_finance'),
        'password' => env('DB_PASSWORD', 'amartuki_finance'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

What’s the solution then ! Anybody help please ?

2

Answers


  1. Chosen as BEST ANSWER

    Solved my problem. It's a very silly mistake.

    After creating user I didn't add the user to my database and that's why user didn't get any privilege.

    Now change those things and the project run successfully.


  2. You should follow following method to load env values in Laravel

    1. load env file

    Dotenv::load(base_path()); // path of your env file

    1. require your values

    Dotenv::required(array(‘DB_PORT’,’DB_HOST’,
    ‘DB_DATABASE’,’DB_USERNAME’, ‘DB_PASSWORD’,’DB_SOCKET’));

    1. assign like below
    'mysql' => [
        'driver' => 'mysql',
        'host' => getenv('DB_HOST'),
        'port' => getenv('DB_PORT'),
        'database' => getenv('DB_DATABASE'),
        'username' => getenv('DB_USERNAME'),
        'password' => getenv('DB_PASSWORD'),
        'unix_socket' => getenv('DB_SOCKET'),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search