dpbvpgvrhwxen3222 2019-03-18 16:38
浏览 279

SQL连接被Laravel拒绝了

I'm aware this can be a recurring question, but none of the solutions i found online seem to be working with my problem.

I have a Laravel 5.8 project but i can't access to my database from a controller, all artisan command works fine (like php artisan migrate)

But when a try a simple thing like:

protected function test()
{
   return User::all();
}

I get SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `users`.`deleted_at` is null)

I simply trying to access my local database (from OSX) My Config :

.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=secret
database.php
'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'database'),
    'username' => env('DB_USERNAME', 'database'),
    'password' => env('DB_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
],

My database is working (i can access it with an IDE or else)

Thanks for your help !

  • 写回答

1条回答 默认 最新

  • douxian9010 2019-03-18 16:53
    关注

    it isn't the best answer, but create new database user with all privileges and use that user.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?