Search code examples
mysqltravis-ci

Travis build fails with error LOAD DATA LOCAL INFILE file request rejected due to restrictions on access


UPD: The question is different from MySQL: Enable LOAD DATA LOCAL INFILE

That question is related to LOCAL run and nothing to do with travis build, locally, using that options everything works like a charm, no problem with it, but running in travis, also requesting mysql not with mysql client, but programmaticaly - so i can't set any client option, this makes my case different.

i am trying to set up travis build - and running into error

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

I tried local_infile option, as i do on my local system:

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

(I tried this option at before install section, at install section)

But still it doesn't help.

I am completly stuck without ideas where to move further. Appreciate any help.

My travis config is following:

 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://[email protected]:3306/ src/tests; fi
  - if [[ "$TESTENV" == "test" ]]; then coverage report -m; fi

Solution

  • The MySQL DSN might accept local_infile=1 as an argument. Example:

    coverage run -m pytest --server=mysql://[email protected]:3306/?local_infile=1 src/tests
    

    I can't confirm this, because the versions of coverage and pytest I have installed don't recognize the --server option. I can't find any documentation of that flag. So I don't know exactly what you're using.

    Also the support for the local_infile option may depend on which database driver you're using, e.g. mysql.connector, pymysql, etc.