gpt4 book ai didi

mysql - 我如何在 mysql docker 服务上创建数据库

转载 作者:行者123 更新时间:2023-11-29 21:47:19 26 4
gpt4 key购买 nike

我正在尝试在我的 gitlab ci 服务器上运行moodle phpunit。使用 gitlab-ci.yml 文件,我正在创建一个带有 php 5.6 和 mysql 服务的容器。

# Services
services:
- mysql:latest

before_script:
- mysql -e 'CREATE DATABASE gitlab_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;

我收到ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)并且不知道如何继续。

最佳答案

Tomasz 这是我的 gitlab-ci.yml 文件,您将需要这样的文件:

# Select image from https://hub.docker.com/r/_/php/
image: php:7.0.0

services:
- mysql:5.7

variables:
# Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
MYSQL_DATABASE: symfony
MYSQL_ROOT_PASSWORD: qwerty

# Composer stores all downloaded packages in the vendor/ directory.
# Do not use the following if the vendor/ directory is commited to
# your git repository.
cache:
paths:
- vendor/

before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
- cp ci/parameters.yml app/config/parameters.yml
- composer install

test:app:
script:
- phpunit

这是我的 ci 文件夹中的 docker_install.sh

#!/bin/bash

# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0

set -xe

# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
apt-get install wget -yqq
apt-get install zip unzip -yqq

# Install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

# Install phpunit, the tool that we will use for testing
curl -o /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit

# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo pdo_mysql mbstring

关于mysql - 我如何在 mysql docker 服务上创建数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34003404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com