我的.env文件中有这个
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
这是在我的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,
],
创建了数据库,我可以在浏览器的phpMyAdmin中看到它。
但是当我写php artisan migrate
时,我收到了这个错误:
[PDOException] SQLSTATE [HY000] [1049]未知数据库' laravel1'
我已经看到了答案 Laravel Migration - Says unknown database, but it is created,但这对我没有帮助。
答案 0 :(得分:3)
尝试指定您正在使用的MySQL端口。可能会锻炼身体。我有类似的问题。一定要在ur系统中给出安装MySQL的相应端口(默认为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,
],