我有Laravel 5.6并尝试从我的虚拟机连接到MySql,但是当我尝试“ php artisan migration”时会出现此错误:
“ Illuminate \ Database \ QueryException:SQLSTATE [HY000] [2002]连接被拒绝”
我的配置很好,因为我可以从主机上进行配置,但是不能从我的虚拟机上进行。
Mysql用户拥有所有权限,并且我具有以下配置: confing / database.php:
'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,
],
config.env
DB_CONNECTION=mysql
DB_HOST=(myIp like x.x.x.x)
DB_PORT=3306
DB_DATABASE=DB_laravel
DB_USERNAME=DB_laravel
DB_PASSWORD=xxxxxx