Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gurvindersingh's avatar

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select count(*) as aggregate from `users` where `email` = [email protected])

I'm trying to register but it shows me this error

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select count(*) as aggregate from users where email = guribhullar8@gmail.com)

GET Data empty POST Data _token "MEvWFDBSvHlVptDqdWGFU7TOJ9HPIrqarw9eDs7z" name "Gurvinder Singh" email "guribhullar8@gmail.com" password "1" password_confirmation "1" Files empty Cookies XSRF-TOKEN "eyJpdiI6ImZjSjRoR2Vtdk1ka0gxZnRqOUhWbFE9PSIsInZhbHVlIjoiemtBZFhvZ0ZxZjduMUlGRjErOUt5K3MxMnFrXC9Qd3VXQjBwZWpHUytoVEtsTFJHOUwyRHYrelwvbk5cLzZOTHR1TiIsIm1hYyI6IjVj ▶" laravel_session "eyJpdiI6IkRLMkJZZ2NndGU0VHhVVUxnNytaTnc9PSIsInZhbHVlIjoiT3E0WUNUVlpDT2pOZG42alM0d3VxTUM2WktNK0ZnR1pmbW11dUt5TlU4QXlmdk9iVCtzRFhVdFwvQTNQWUI5bWwiLCJtYWMiOiJkNDA3 ▶" Session empty Server/Request Data DOCUMENT_ROOT "C:\xampp\htdocs\blog\public" REMOTE_ADDR "127.0.0.1" REMOTE_PORT "56521" SERVER_SOFTWARE "PHP 7.2.9 Development Server" SERVER_PROTOCOL "HTTP/1.1" SERVER_NAME "127.0.0.1" SERVER_PORT "8000" REQUEST_URI "/register" REQUEST_METHOD "POST" SCRIPT_NAME "/index.php" SCRIPT_FILENAME "C:\xampp\htdocs\blog\public\index.php" PATH_INFO "/register" PHP_SELF "/index.php/register" HTTP_HOST "127.0.0.1:8000" HTTP_CONNECTION "keep-alive" CONTENT_LENGTH "134" HTTP_CONTENT_LENGTH "134" HTTP_CACHE_CONTROL "max-age=0" HTTP_ORIGIN "http://127.0.0.1:8000" HTTP_UPGRADE_INSECURE_REQUESTS "1" CONTENT_TYPE "application/x-www-form-urlencoded" HTTP_CONTENT_TYPE "application/x-www-form-urlencoded" HTTP_USER_AGENT "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" HTTP_ACCEPT "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8" HTTP_REFERER "http://127.0.0.1:8000/register" HTTP_ACCEPT_ENCODING "gzip, deflate, br" HTTP_ACCEPT_LANGUAGE "en-US,en;q=0.9" HTTP_COOKIE "XSRF-TOKEN=eyJpdiI6ImZjSjRoR2Vtdk1ka0gxZnRqOUhWbFE9PSIsInZhbHVlIjoiemtBZFhvZ0ZxZjduMUlGRjErOUt5K3MxMnFrXC9Qd3VXQjBwZWpHUytoVEtsTFJHOUwyRHYrelwvbk5cLzZOTHR1TiIsI ▶" REQUEST_TIME_FLOAT 1536234525.7375 REQUEST_TIME 1536234525

0 likes
19 replies
gurvindersingh's avatar

and this is my db configuration in.env file

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=blog DB_USERNAME=root DB_PASSWORD=

faizaltkl's avatar

what is your configuration in app/database.php? localhost or 127.0.0.1?

gurvindersingh's avatar

Hi @faizaltkl

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            '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' => '',
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => 'predis',

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],

        'cache' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_CACHE_DB', 1),
        ],

    ],

];
gurvindersingh's avatar

I posted all the content of database.php file in previous comment

can you please check it if anything wrong here

jackdrak's avatar
jackdrak
Best Answer
Level 1

The problem is clearly in the error:

Access denied for user 'homestead'@'localhost'

The server is trying to connect using the homestead username. You have either not created a user named homestead in mysql or have a different password set.

2 likes
gurvindersingh's avatar

hi @jackdrak,

thanks for response

can you please tell me why it using homestead here instead of 'root' defined in .env file

it's working fine in older versions of laravel but not working in this 5.7 ver of laravel

gurvindersingh's avatar

@faizaltkl

sorry for late response.

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:7om5iWcStIRSgamMZxUD74StMwRG1PL9OIcdIiVlJss=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

ryanborum's avatar

@gurvindersingh You might be editing your example .env instead of your actual.

If you have the correct one, you may need to stop and restart your application if you're using php artisan serve so that it can load new credentials from the .env file

Another issue you may experience, for newer versions of MySQL (5.8<, I think), the default account is no longer "root" with no password. A password is randomly generated when installed. You can change that password here if you lost/ never recorded the temp:

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

livesinspb's avatar

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

This means you should use the password for root user. Because root user has a password!

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=**there must be a password**

profit :)

3 likes
Miniraj's avatar

close your Laravel development server in cli using ctrl+c. Then restart your server with "php artisan serve" .

1 like
felex's avatar

After editing my .env file,i restarted my server which helped me to get rid of the problem

Tray2's avatar

Shared hosting usually isn't restartable by you.

I suggest you start a new thread and describe your issues.

alvaromoca1's avatar

algo tan simple muchas veces nos demora mas tiempo que lo demás, cuando el password que configuras en el .env esta con { o @ o signos extraños es mejor que esa contraseña lo coloques dentro de una ' ' quedaría de esta forma DB_PASSWORD='password_of_BD' y creeme que te funcionara normal

1 like

Please or to participate in this conversation.