Bitbucket管道导入mysql模式

发布于 2025-01-28 02:49:19 字数 4331 浏览 2 评论 0 原文

我正在尝试通过以下语句将数据库架构导入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&lt; db_schema.sql
错误:没有这样的容器:mysql

使用MySQL的最佳方法是什么,以便我可以将DB的立场导入到测试目的中?如何?

请在下面找到.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

I'm trying to import database schema to mysql service through following statement

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

and it returns "mysql: not found". I have even tried the following command

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

Even though received error

docker exec -i mysql mysql --user=$DB_USERNAME --password=$DB_PASSWORD 5i < DB_Schema.sql
Error: No such container: mysql

What would be the best way to use mysql so that I can import a stance of DB into it for testing purpose and how?

enter image description here

Please find the .yml file below.

# 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对岸观火 2025-02-04 02:49:19

您不能在第一步中安装/更新/更改主图像,以便他们在最后一步中存在。使用所有这些安装进行自定义的Docker映像,这将使运行管道的速度更快,并让您在管道中使用其他工具。

You cannot install/update/change you main image in the first step for them to be there in the last step. Make your custom Docker image with all those installations, which will make it faster to run the pipeline and will let you use other tools you need in your pipeline.

無處可尋 2025-02-04 02:49:19

我更喜欢使用“ MySQL”客户端 fofer docker,并基于 port 映射设置,将其伸入Docker容器。然后,从概念上讲,就像在单独的“服务器”上读取“ mySQLD”服务器一样。

加载数据infile 插入,包括使用 mysql ...&lt; dump.sql 工作正常。

I prefer to use the "mysql" client outside Docker and have it reach into the Docker container based on the port mapping set up. Then, conceptually, it is like reading to a "mysqld" server on a separate "server".

LOAD DATA INFILE and INSERT, including use of mysql ... < dump.sql works fine.

┾廆蒐ゝ 2025-02-04 02:49:19

我相信此错误是因为 mySQL 在您使用的Docker容器中没有可用。此命令可能来自MySQL-CLIENT软件包,要么安装此命令或使用默认情况下可用的容器映像。

I believe this error is because mysql isn't available within the docker container you're using. This command may come from the mysql-client package, either install this or use a container image that has it available by default.

https://support.atlassian.com/bitbucket-cloud/docs/use-docker-images-as-build-environments/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文