mysql - Travis 构建失败,并出现错误 LOAD DATA LOCAL INFILE 文件请求因访问限制而被拒绝

标签 mysql travis-ci

UPD:这个问题与 MySQL: Enable LOAD DATA LOCAL INFILE 不同

这个问题与本地运行有关,与本地的 travis 构建无关,使用该选项一切都像魅力一样,没有问题,但在 travis 中运行,也请求 mysql 不使用 mysql 客户端,而是以编程方式 -所以我无法设置任何客户端选项,这使我的情况有所不同。

我正在尝试设置 travis build - 并遇到错误

MySQLdb.OperationalError: (2068, 'LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.')

我尝试了 local_infile 选项,就像我在本地系统上所做的那样:

mysql -u root -h localhost -e 'SET GLOBAL local_infile=1'

(我在安装之前部分、安装部分尝试过此选项)

但是仍然没有帮助。

我完全不知道该往哪里走。感谢任何帮助。

我的 travis 配置如下:

 language: python
os: linux
dist: jammy

services:
  - mysql

python:
  - "3.10.5"

env:
  - TESTENV=test

before_install:
  - mysql -u root -h localhost -e 'GRANT ALL PRIVILEGES ON *.* TO "travis"@"%"'
install:
  - pip3 install --upgrade pip
  - pip3 install --upgrade setuptools wheel
  - mysql -u root -h localhost -e 'SET GLOBAL local_infile=1'
  - pip3 install -r requirements.txt
  - if [[ "$TESTENV" != "docs" ]]; then pip3 install -r requirements-test.txt; fi
  - pip3 install -e .

script:
  - if [[ "$TESTENV" == "test" ]]; then coverage run -m pytest --server=mysql://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43373122352a30037271746d736d736d72" rel="noreferrer noopener nofollow">[email protected]</a>:3306/ src/tests; fi
  - if [[ "$TESTENV" == "test" ]]; then coverage report -m; fi

最佳答案

MySQL DSN 可能接受 local_infile=1 作为参数。示例:

coverage run -m pytest --server=mysql://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e0949281968993a0d1d2d7ced0ced0ced1" rel="noreferrer noopener nofollow">[email protected]</a>:3306/?local_infile=1 src/tests

我无法确认这一点,因为我安装的 coveragepytest 版本无法识别 --server 选项。我找不到该标志的任何文档。所以我不知道你到底用的是什么。

此外,对 local_infile 选项的支持可能取决于您使用的数据库驱动程序,例如mysql.connector、pymysql等

关于mysql - Travis 构建失败,并出现错误 LOAD DATA LOCAL INFILE 文件请求因访问限制而被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76137482/

相关文章:

PHP: try catch 异常

php - 我可以在 MySQL 中使用 Distinct 和 Union All 吗?

cocoapods - 我可以在 Podfile 中使用 Travis 环境变量吗?

c++ - Travis CI 上 Boost 中对 `std::__cxx11::basic_string 的 undefined reference

mocha.js - Travis ci 使用 mocha+coveralls 失败

php - mysql innodb db varbinary 的正确索引类型是什么?

php - $mysqli->affected_rows 返回 0 multi_query

mysql - 我如何处理这个棘手的 MySQL 查询 [根据同一表的优先级连接]?

maven - 在 Maven 中使用嵌入式数据库与 Flyway 和 jOOQ 进行持续集成

travis-ci - Travis 构建后/dist 目录在哪里?