Bitbucket管道导入mysql模式
我正在尝试通过以下语句将数据库架构导入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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在第一步中安装/更新/更改主图像,以便他们在最后一步中存在。使用所有这些安装进行自定义的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.
我更喜欢使用“ 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
andINSERT
, including use ofmysql ... < dump.sql
works fine.我相信此错误是因为
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/