Configure MySQL for LOAD DATA LOCAL

Here is how to configure MySQL so you can load data without getting the following error:

Loading local data is disabled; this must be enabled on both the client and server sides

In my example, I’m running MySQL 8 in a Docker Swarm and connecting using the command-line client.

On the server side, you need to set local-infile to ON.

Here is what the MySQL section of the compose file looks like. Note the setting has been added to the command: section.

mysql:
  image: mysql:8.0.22
  command: --default-authentication-plugin=mysql_native_password --local-infile=ON
  hostname: mysql
  ports:
    - "3306:3306"
  volumes:
    - mysql_data:/var/lib/mysql
  environment:
    MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_password
  secrets:
    - mysql_password

On the client side, you have to set local-infile=1. This can be done directly in the call to the client

mysql --local-infile=1 

or you can set it in the configuration file

mysql --defaults-extra-file=./mysql.conf 

with the configuration file (ex: mysql.conf) set something like this:

[client]
host = <your hostname>
user = <your username>
password = <your password>
local-infile=1

With these two settings, you should be good to go!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.