QueryException SQLSTATE [HY000] [2002]连接被拒绝

时间:2018-05-16 04:53:01

标签: php mysql laravel macos laravel-5

我无法使用Laravel连接到数据库。

PHP版本:7.1.10 MAC OSX

错误:

Whoops, looks like something went wrong.
(2/2) QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: SELECT * FROM project_categories WHERE status='A')

in Connection.php (line 647)
at Connection->runQueryCallback(object(Expression), array(), object(Closure))
in Connection.php (line 607)
at Connection->run(object(Expression), array(), object(Closure))
in Connection.php (line 326)
at Connection->select(object(Expression))
in DatabaseManager.php (line 324)`

ENV SETTINGS

APP_NAME=Somesite
APP_ENV=local
APP_KEY=base64:hFfau6WVxgBJ7GCmvnOK+GZd9/MuIy03zAqNCO8VTO8=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=somesite
DB_USERNAME=root
DB_PASSWORD=

Database.php配置:

        mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'mahijaa'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

关注此主题:https://github.com/laravel/framework/issues/19522找到解决方案但没有用处。我做错了什么,是我的代码或环境的问题。相同的代码在Windows机器上工作得非常好。最近迁移到mac OS,所有人都继续折腾

0 个答案:

没有答案