Laravel 8 数据库连接拒绝 MacBook
Posted
技术标签:
【中文标题】Laravel 8 数据库连接拒绝 MacBook【英文标题】:Laravel 8 Database Connection refused MacBook 【发布时间】:2021-05-07 22:03:47 【问题描述】:我有一个大问题阻止我从事该项目。我无法使用我的 Mac 连接到数据库。
Error: connection refused
实际上,我在 Xampp 上,IP 地址为:192.168.64.2,mysql 在 localhost:8080 ->80(通过 SSH)上运行。 Laravel 项目不在 Xampp 文件中,只是在我的桌面上。它运行在:
Location of my project
我的 .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=80
DB_DATABASE=cartographie
DB_USERNAME=root
DB_PASSWORD=
【问题讨论】:
端口 80 和 8080 通常与网络服务器 (http) 相关联,而不是与 mysql 相关联。你确定你的端口是对的吗? 嗨,你试过这个解决方案吗***.com/questions/35394230/… 【参考方案1】:我想我有先见之明,我设法理解了 Docker 的用处。
所以我把 docker-compose.yml 文件放在下面给大家启发:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '$WWWGROUP'
image: sail-8.0/app
ports:
- '$APP_PORT:-80:80'
environment:
WWWUSER: '$WWWUSER'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
# - selenium
# selenium:
# image: 'selenium/standalone-chrome'
# volumes:
# - '/dev/shm:/dev/shm'
# networks:
# - sail
# depends_on:
# - laravel.test
mysql:
image: 'mysql:8.0'
ports:
- '$FORWARD_DB_PORT:-3306:3306'
environment:
MYSQL_ROOT_PASSWORD: '$DB_PASSWORD'
MYSQL_DATABASE: 'cartographie'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '$FORWARD_REDIS_PORT:-6379:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
# memcached:
# image: 'memcached:alpine'
# ports:
# - '11211:11211'
# networks:
# - sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
.env
APP_NAME="Agents Centrimex"
APP_ENV=local
APP_KEY=base64:WKnFZG6Qz2rEsYY+kk9kIl2Fw8l5HBa97edgqqjx4d0=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8000
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cartographie
DB_USERNAME=root
DB_PASSWORD=root
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
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=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=support@centrimex.com
MAIL_PASSWORD=Vitrolles13127
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=support@centrimex.com
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"
【讨论】:
以上是关于Laravel 8 数据库连接拒绝 MacBook的主要内容,如果未能解决你的问题,请参考以下文章
Laravel:SQLSTATE [HY000] [2002] 连接被拒绝
连接拒绝 docker、laravel 和 mysql 服务器
将 Laravel 部署到 Elastic Beanstalk - 数据库连接被拒绝
PHP + MYSQL + Laravel - “SQLSTATE [HY000] [2002] 连接被拒绝” [重复]