doukun8670 2015-07-05 12:09
浏览 233
已采纳

SQLSTATE [HY000] [2002]连接仅在使用laravel 5的工匠中被拒绝

I'm running a vagrant box and with laravel 5. For some reason when running php artisan it throws the following error:

SQLSTATE[HY000] [2002] Connection refused

This happens when I have my host set to 127.0.0.1. When using localhost I get File or directory not found.

The strange part is that the website itself works fine in the browser. This only happens in php artisan.

I also tried changing ports between 3306 and 33060.

Any ideas?

EDIT: I did the following in the laravel index.php file:

$pdo = new PDO('mysql:host=127.0.0.1;dbname=mydb','root','mypassword');
var_dump(get_class_methods($pdo));
die();

and it worked fine. Inside the Connector.php file I checked the variables being passed to the PDO constructor and they were identical to what I filled in above. What is going on?

  • 写回答

1条回答 默认 最新

  • dongzhilian0188 2015-07-05 13:13
    关注

    I can't believe I am posting this but I was in the wrong terminal tab. Instead of running php artisan on the VM i was running it directly in OSX... Obviously it won't connect to a database that does not exists.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?