Bitbucket管道导入mysql模式

问题描述 投票:0回答:2

我正在尝试通过以下语句将数据库架构导入到 mysql 服务

mysql -h 127.0.0.1 -u $DB_USERNAME -p$DB_PASSWORD $DB_DATABASE < DB_Schema.sql

它返回“mysql:未找到”。我什至尝试过以下命令

docker exec -i mysql mysql -h 127.0.0.1 -u $DB_USERNAME -p$DB_PASSWORD $DB_DATABASE < DB_Schema.sql

即使收到错误

docker exec -i mysql mysql --user=$DB_USERNAME --password=$DB_PASSWORD 5i < DB_Schema.sql
错误:没有这样的容器:mysql

使用 mysql 的最佳方法是什么,以便我可以将数据库的立场导入其中以进行测试以及如何操作?

请找到下面的 .yml 文件。

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----

# Specify a docker image from Docker Hub as your build environment.
# All of your pipeline scripts will be executed within this docker image.

image: php:8.0-fpm-alpine

# All of your Pipelines will be defined in the `pipelines` section.
# You can have any number of Pipelines, but they must all have unique
# names. The default Pipeline is simply named `default`.

pipelines:
  default:
  # Each Pipeline consists of one or more steps which each execute
  # sequentially in separate docker containers.
  # name: optional name for this step
  # script: the commands you wish to execute in this step, in order
    - parallel:
      - step:
          name: Installing Dependancies and Composer
          caches:
            - composer
          script:
            # Your Pipeline automatically contains a copy of your code in its working
            # directory; however, the docker image may not be preconfigured with all
            # of the PHP/Laravel extensions your project requires. You may need to install
            # them yourself, as shown below.
            - apt-get update && apt-get install -qy git curl libmcrypt-dev unzip libzip-dev libpng-dev zip git gnupg gnupg2 php-mysql
            - docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg --with-webp && \
            - docker-php-ext-install gd && \
            - docker-php-ext-install exif && \
            - docker-php-ext-install zip && \
            - docker-php-ext-install pdo pdo_mysql
            - rm -rf ./vendor
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install --ignore-platform-reqs
            - composer dump-autoload
            # Here we create link between the .env.pipelines file and the .env file
            # so that our database can retrieve all the variables inside .env.pipelines
            - ln -f -s .env.pipelines .env
          artifacts:
            - vendor/**

      - step:
          name: Installing and Running npm
          image: node:16
          caches:
            - node
          script:
            - npm install -g grunt-cli
            - npm install
            - npm run dev
          artifacts:
            - node_modules/**

    - step:
        name: Running Test
        deployment: local
        script:
          # Start up the php server so that we can test against it
          - php artisan serve &
          # # Give the server some time to start
          - sleep 5
          # - php artisan migrate
          - docker ps
          - docker container ls
          - mysql -h 127.0.0.1 -u $DB_USERNAME -p$DB_PASSWORD $DB_DATABASE < DB_Schema.sql
          # - docker exec -i mysql mysql -h 127.0.0.1 -u $DB_USERNAME -p$DB_PASSWORD -e "SHOW DATABASES"
          - php artisan optimize
          - php artisan test
        services:
          - mysql
          - docker
          
# You might want to create and access a service (like a database) as part
# of your Pipeline workflow. You can do so by defining it as a service here.
definitions:
  services:
    mysql:
      image: mysql:latest
      environment:
        MYSQL_DATABASE: $DB_DATABASE
        MYSQL_USER: $DB_USERNAME
        MYSQL_PASSWORD: $DB_PASSWORD
        MYSQL_ROOT_PASSWORD: $DB_PASSWORD
        SERVICE_TAGS: mysql
        SERVICE_NAME: mysql
mysql dockerfile bitbucket-pipelines
2个回答
0
投票

您无法在第一步中安装/更新/更改主映像,以便它们在最后一步中出现。使用所有这些安装制作自定义 Docker 映像,这将使运行管道的速度更快,并允许您使用管道中所需的其他工具。


0
投票

我更喜欢使用“mysql”客户端outsideDocker,并让它根据设置的

port
映射进入Docker容器。然后,从概念上讲,这就像在单独的“服务器”上读取“mysqld”服务器。

LOAD DATA INFILE
INSERT
,包括使用
mysql ... < dump.sql
效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.