manbetx客户端打不开CI mysql连接

时间:2019-06-03 11:07:17

标签: python sqlalchemy gitlab

我正在尝试使用其共享的运行程序连接到MySQL。我编写了以下代码:

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://' +  db_username + ":" + db_password + "@" + db_host + ":" + db_port + "/" + db_name + "?host="+ db_host + "?port=" + db_port

db_username = XXX
db_password = XXX
db_host = mysql
db_port = 3306
db_name = XXX

以及以下.gitlab-ci.yml:

image: python:3.6-stretch

services:
  - mysql:latest

variables:
  FLASK_APP: "program.py"
  MYSQL_DATABASE: XXX
  MYSQL_ROOT_PASSWORD: "XXX"

install_dependencies:
  stage: build
  script:
    - apt update && apt upgrade -y
    - pip install pipenv
    - pipenv install

run_unit_tests:
  stage: test
  script:
    - apt update && apt upgrade -y
    - pip install pipenv
    - pipenv install
    - pipenv run pytest -s

跑步者启动时,我在run_unit_tests作业中遇到以下错误:

'Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' 

1 个答案:

答案 0 :(得分:-1)

您是否已将python应用程序配置为使用数据库主机mysql

Host: mysql
User: root

如果这样做没有帮助,请先尝试在Python映像中安装mysql-client

install_dependencies:
  stage: build
  script:
    - apt update && apt upgrade -y && apt install -y mysql-client
    - pip install pipenv
    - pipenv install