php - 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", [])
解决方案
Best to use the IP so it's connectible from both remote CLI and your local machine
'host' => '192.168.10.10',
推荐阅读
- javascript - 在 javascript 中使用条件编写扩展运算符的更好方法
- javascript - 当尝试在markdown编辑器中连续多次上传相同的图像时,第一次上传但第二次没有上传
- sql - 雪花日期格式更改
- docker - Docker Container 内的上传速度限制为 4 Mbit/s
- php - 单击图标可在浏览器中查看 word 或 excel
- php - 如何在php codeigniter中将整数数据从数据库转换为字符串
- r - R 在胶水语句中使用 bang-bang
- javascript - 在条形图javascript中显示值
- php - html 复选框数组在更改时生成额外的数组元素
- r - 如何在R中为y轴自定义间距?