简体   繁体   English

Docker Laravel 迁移错误 Illuminate\Database\QueryException SQLSTATE[HY000]

[英]Docker Laravel migration error Illuminate\Database\QueryException SQLSTATE[HY000]

I have this error when running php artisan migrate:fresh:运行 php artisan migrate:fresh 时出现此错误:

#15 0.576    Illuminate\Database\QueryException 
#15 0.576   SQLSTATE[HY000] [2002] No such file or directory (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

My docker-compose.yml:我的 docker-compose.yml:

version: "3.7"

networks:
  app-network:
    driver: bridge

services:
  app:
    build:
      context: ./
      dockerfile: Dockerfile
    image: laravel8-php-fpm-80
    container_name: app
    restart: unless-stopped
    tty: true
    working_dir: /var/www
    volumes:
      - ./:/var/www
    networks:
      - app-network

  db:
    image: mysql:5.7.33
    container_name: db
    restart: unless-stopped
    tty: true
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      SERVICE_TAGS: dev
      SERVICE_NAME: db
    volumes:
      - ./mysql/data:/var/lib/mysql
    networks:
      - app-network

  nginx:
    image: nginx:1.19.8-alpine
    container_name: nginx
    restart: unless-stopped
    tty: true
    ports:
      - 8100:80
    volumes:
      - ./src:/var/www
      - ./nginx/conf:/etc/nginx/conf.d
    networks:
      - app-network

My Dockerfile:我的 Dockerfile:

FROM php:8.0.3-fpm-buster

RUN docker-php-ext-install bcmath pdo_mysql

RUN apt-get update
RUN apt-get install -y git zip unzip
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . /var/www
WORKDIR /var/www
RUN composer install
RUN php artisan config:clear
RUN php artisan migrate:fresh

EXPOSE 9000

My env file:我的环境文件:

APP_NAME=App Name
APP_ENV=local
APP_KEY=base64:1XGhFF8+2qNi2IPyQVgdv783pZqTgsUl4Y77K9gUoYY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=root
DB_PASSWORD=123456

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
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}"

in my config/database.php I got:在我的 config/database.php 我得到:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', 'forge'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

I'm new in docker, so maybe I'm missing something.我是 docker 的新手,所以也许我遗漏了一些东西。 Does anyone know what may be the problem here:( I spent two days investigating this error and didn't find any good answer有谁知道这里可能是什么问题:(我花了两天时间调查这个错误并没有找到任何好的答案

I find a solution by running bash script like this:我通过运行 bash 脚本找到了一个解决方案,如下所示:

#!/bin/bash
echo "Migration Started";
 php artisan migrate
 echo "Seeding started"
 php artisan db:seed
 echo "Server starting"
return

but now I have problem because my migrations are running in loop, migrating never stops.但现在我遇到了问题,因为我的迁移是循环运行的,迁移永远不会停止。 I don't know why it behaves like this.我不知道为什么它会这样。 Does anyone know a solution to this migration in loop problem?有谁知道这种循环迁移问题的解决方案? I also tried with adding php artisan serve before return statement and migrations finished and server does start, but then my problem is I cannot open application on port 8100, I think its because of artisan serve.我还尝试在返回语句和迁移完成并且服务器启动之前添加 php artisan serve,但是我的问题是我无法在端口 8100 上打开应用程序,我认为这是因为 artisan serve。

I will mark this code I put above as a solution for problem I had, although it create other kind of problem now, but for that I created new issue here on Stackoverflow.我将把我放在上面的这段代码标记为我遇到的问题的解决方案,尽管它现在会产生其他类型的问题,但为此我在 Stackoverflow 上创建了新问题。

You solved my day.你解决了我的一天。 I have the same problem: When I run the command "php artisan migrate,fresh --seed".我有同样的问题:当我运行命令“php artisan migrate,fresh --seed”时。 it returns "Connection refused" at a given time, When I run separate: "php artisan migrate:fresh" and then "php artisan db,seed".它在给定时间返回“连接被拒绝”,当我单独运行时:“php artisan migrate:fresh”,然后是“php artisan db,seed”。 everything is perfect.一切都很完美。 I'm not understanding anything我什么都不懂

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 6-MariaDB 10.1:Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]迁移错误 - Laravel 6 - MariaDB 10.1: Illuminate\Database\QueryException : SQLSTATE[HY000] migration error Laravel 6 - Mysql - Docker - Illuminate\Database\QueryException SQLSTATE[HY000]:一般错误:2036 - Laravel 6 - Mysql - Docker - Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 2036 Illuminate\Database\QueryException:SQLSTATE[HY000]:一般错误:1813 Tablespace for table - Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1813 Tablespace for table php artisan migrate - 错误 - Illuminate\Database\QueryException: SQLSTATE[HY000] [2054] - php artisan migrate - Error - Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table - 在克隆项目中 - Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] 在文件 Illuminate/Database/Connection.php 上的第 678 行 - Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] in file Illuminate/Database/Connection.php on line 678 Illuminate \\ Database \\ QueryException (2002) SQLSTATE[HY000] [2002] 没有这样的文件或目录 (SQL: select * from `rents`) - Illuminate \ Database \ QueryException (2002) SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `rents`) 如何修复“Illuminate\\Database\\QueryException: SQLSTATE[HY000] [1044] Access denied for user” - How to fix “Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user” Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (使用密码: YES) - Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) php artisan migrate Illuminate\\Database\\QueryException SQLSTATE[HY000] [2054] 上的异常 - Exception on php artisan migrate Illuminate\Database\QueryException SQLSTATE[HY000] [2054]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM