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

ignisrzeus's avatar

Access denied for user 'forge'@'localhost' (using password: YES)

Good Day Laracasts!

Today is my first time deploying a website via Laravel Forge. I've been following BitFumes' guide on how to deploy a laravel app via Forge, and everything has been working fine up until the database connection.

I have successfully logged in via SSH in my database, but whenever i run

mysql -uforge -p

I always get the result:

Access denied for user 'forge'@'localhost' (using password: YES)

The password that I input is the one that is located in the .env file in the Laravel Forge Environment section.

Currently stuck as i cannot successfully access my database because of this dilemma.

As of the moment, I'm not sure what I need to show you guys, but i simply named my database "forge" and didn't change anything as of the moment as i tried to strictly follow BItFumes' guide.

However, these are crucial files that I think are related to my dilemma:

database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            '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' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

config\app.php

 'key' => env('APP_KEY'),

.env

APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:Jihb8EG1he78Cv5ZhG8CRxAfyic3bWm+FetJbXWTqPg=
APP_DEBUG=false
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD="somerandomgeneratedpassword"

As I have stated above, I copy and simply paste "somerandomgeneratedpassword" (Obv. a placeholder) in the password section when being asked after running "mysql -uforge -p".

Any help will be greatly appreciated. Thank you very much!

0 likes
8 replies
bobbybouwmann's avatar

By default, Laravel Forge creates a database called forge, but not a user called forge. You only start with a root user and a root password. You can use the root user and password as credentials for testing for now.

However, this is not secure for production. This user has access to all databases. Instead, you should create a separate user for each database. You can do that on the server page in Forge. Create a new user there with a new strong password and use those credentials. Make sure to connect this user to that database in the UI as well.

ignisrzeus's avatar

Hi! Thank you for the response!

I checked my database users and confirmed that Laravel Forge created user "forge" right away after creating the "forge" server.

And also, i can confirm that user "forge" exists because I was able to access the database via SSH. My terminal now starts at:

forge@mywebsite

My problem occurs when entering the DB_PASSWORD, it seems as if it the .env is not reflecting the correct DB_PASSWORD unfortunately.

forge@mywebsite:~$ mysql -uforge -p
Enter password:
ERROR 1045 (28000): Access denied for user 'forge'@'localhost' (using password: YES)

If i am assuming the wrong things, I apologize in advance as I am new to deploying Laravel Applications. Hopefully I made sense. Thank you!

bobbybouwmann's avatar

Are you sure you're using the correct password here? There is a root password emailed to you, but that is not the same as the forge password. To login with the root user you can do this

mysql -root -p
ignisrzeus's avatar

Hi! I'm completely lost here. I'm very sorry for being clueless about Laravel Forge. Few questions here

  1. When Enter Password prompts in:
forge@mywebsite:~$ mysql -uforge -p
Enter password:

What password should I input? From my understanding, I am supposed to input the DB_PASSWORD under the .env file -- which is the same password that is emailed to be by Laravel Forge.

  1. In relation to 1, when prompted for the password of root, I do not know what I am supposed to input. I checked my email, and I did not receive a password for root unfortunately.

Here's a sample of the email I got from Laravel Forge

Name:	SomeWebsiteName
IP Address:	SomeIPAddress
Username:	forge
Sudo Password:	SomeSudoPassword
Database Username:	forge
Database Password:	SomeDBPassword

This is the only email I received that has a password inloved in it.

Hope this helps clarify things. Thanks!

bobbybouwmann's avatar

Mmh, yeah that passport should work. Unless you changed it in the UI of Forge of course. You can always reset the password to that password you got in the email. By default, this user should have access to all databases, but again you can configure that on the database tab per server.

ignisrzeus's avatar

I see. I'm seeing some related issues regarding Laravel Forge not retrieving the correct .env file. Could this be related to my issue?

Can't seem to move forward because of this dilemma. Any additional help would be amazing. Thanks!

bobbybouwmann's avatar

If it's a .env the issue, make sure to run php artisan config:clear on your server.

However, it doesn't seem to be a .env issue since can't log in on MySQL using the same credentials.

Please or to participate in this conversation.