php - 为什么 php artisan migrate 会导致“ Illuminate\Database\QueryException SQLSTATE[HY000] [2002] Connection denied”
问题描述
我试图建立一个 Laravel 项目,但是每当我点击php artisan migrate它都会导致这个错误
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = src and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
+36 vendor frames
37 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
我在 WSL Ubuntu 20.04LTS 中使用 laravel/framework:^8.12。我知道这是一个非常常见的问题,但没有一个解决方案对我有用。
我的 .env 文件
APP_NAME=Laravel APP_ENV=本地 APP_KEY=APP_DEBUG=true APP_URL=http://localhost
LOG_CHANNEL=堆栈 LOG_LEVEL=调试
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=src DB_USERNAME=root DB_PASSWORD=
BROADCAST_DRIVER=日志 CACHE_DRIVER=文件 QUEUE_CONNECTION=同步 SESSION_DRIVER=文件 SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379
MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET=
PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
解决方案
推荐阅读
- nginx - Nginx 从 https 重定向到 http
- javascript - 如何减少 1 秒到给定时间
- python - Python & subprocess - 以用户身份打开终端会话并执行一/两个命令
- python - 如何恢复 url 中的文本并将文本转换回来?
- ios - 动画切换 CollectionViewLayout
- python - xml中的注释转换为json?
- java - 如何将@Propertysource 文件转换为地图?
- redis - 来自不同日志文件中不同应用程序的 Celery 任务
- django - Celery RuntimeError: populate() 不可重入
- angular - 使用 Angular 7 + Webpack 4 封装 css