I have this in my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=m6twKy7Lr6KKFvVa7QgXUe78xfn08MLn
DB_HOST=localhost
DB_DATABASE=laravel1
DB_USERNAME=root
DB_PASSWORD=somepass
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
And this is in my database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
The database is created and I can see it in phpMyAdmin in browser.

But when I write php artisan migrate I get this error:
[PDOException] SQLSTATE[HY000] [1049] Unknown database 'laravel1'
I have seen the answers on Laravel Migration - Says unknown database, but it is created , but that didn't helped me.
Try specifying the MySQL port that you are using. Might work out. I had a similar issue like this. Be sure to give the appropriate port where MySQL is installed in ur system(default is 3306).
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'databasename'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With