首页 > 解决方案 > Laravel + Homestead SQLSTATE[HY000] [2002] No conection possible

问题描述

I already tried every tipp in this stackoverflow Thread. But I stil have issues conecting to my MysqlServer on Homestead (based on Vagrant).

I used step by step guide from Learning Laravel

This is how i start my Homestead and Mysql

vagrant up
vagrant ssh
mysql -u homestead -p
mysql> show Databases

(and homestead is showed so the Database exists)

this is my .env:

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

this is my 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' => false,
    'engine' => null,
],

Failure log (sorry its partly in german):

SQLSTATE[HY000] [2002] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte.
 (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

PDOException::("SQLSTATE[HY000] [2002] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte.")

PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead", "homestead", "secret", [])

标签: phpmysqllaravelhomestead

解决方案


Best to use the IP so it's connectible from both remote CLI and your local machine

'host' => '192.168.10.10',

推荐阅读