Laravel and database configuration

Hello,
In a Laravel project, the database.php file looks like this:

'mariadb' => [
            'driver' => 'mariadb',
            'url' => env('DB_URL'),
            'host' => env('DB_HOST', 'db'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'laravel'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => env('DB_CHARSET', 'utf8mb4'),

I want to create an .env file like below:

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

What should the name of DB_DATABASE and DB_USERNAME be? Should this information be the same as the database.php file?

Thank you.

TLDR: Yes, they would be the same.

The reference to DB_DATABASE in this case is the name of the database inside the mysql server that the connection will default into using.
The reference to DB_USERNAME in this case is the name of a user inside the mysql server that would have access to the previously mentioned database.

1 Like

Hello,
Thank you so much for your reply. So:

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

Right?