Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python GitLab CI mysql连接_Python_Sqlalchemy_Gitlab_Gitlab Ci - Fatal编程技术网

Python GitLab CI mysql连接

Python GitLab CI mysql连接,python,sqlalchemy,gitlab,gitlab-ci,Python,Sqlalchemy,Gitlab,Gitlab Ci,我正在尝试使用他们的共享跑步者连接到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_h

我正在尝试使用他们的共享跑步者连接到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
运行程序启动时,运行单元测试作业中出现以下错误:

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

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

Host: mysql
User: root
如果这没有帮助,请先尝试在python映像中安装
mysql客户端

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