简体   繁体   中英

SQL Connection refused with 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 !

这不是最佳答案,但是请创建具有所有特权的新数据库用户并使用该用户。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM