1

I'm pretty new to SQL, MySQL and Docker. I'm running a Docker MySQL container (I believe).

My problem:

In MySQL, the command

select * from [tablename] into outfile [csv-filename];

fails with the message

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

What I've tried:

select @@GLOBAL.secure_file_priv;

outputs a value of NULL.

Then, I changed/added the line

secure_file_priv= "/home/"

into both of the following files within the container:

  • /etc/mysql/my.cnf
  • /etc/mysql/conf.d/docker.cnf

Still, "select @@GLOBAL.secure_file_priv;" in MySQL returns NULL and "(...) into outfile (...);" fails as described above.

Any clues are much appreciated!

1 Answer 1

0

It could be you missed the [mysqld] section for the configuration file however here is a complete example:

$ mkdir conf
$ mkdir home
$ mkdir datadir
$  echo -e '[mysqld]\nsecure_file_priv= "/home/"' | tee conf/native.cnf
[mysqld]
secure_file_priv= "/home/"

$ cat conf/native.cnf
[mysqld]
secure_file_priv= "/home/"

$ docker run -v $PWD/conf:/etc/mysql/conf.d \
             -v $PWD/home:/home  \
             -v $PWD/datadir:/var/lib/mysql \
             -e MYSQL_ROOT_PASSWORD=my-secret-pw \
             --name mysql \
             mysql:5.7

Another terminal:

$  docker exec -ti mysql  mysql -pmy-secret-pw -e 'select @@GLOBAL.secure_file_priv'

mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------------+
| @@GLOBAL.secure_file_priv |
+---------------------------+
| /home/                    |
+---------------------------+
6
  • This indeed works, but now how do I change the secure_file_priv variable in an exisiting container?
    – Nico Autia
    Commented Apr 18, 2020 at 15:29
  • You generally don't. You recreate the container with the right configuration, this way it is repeatable. Note database container can have volume mounts for /var/lib/mysql to preserve data, or use the initialization aspects of the container.
    – danblack
    Commented Apr 18, 2020 at 23:53
  • I'm getting closer! Adding the volume with docker run as suggested gives me the fatal error "InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800!" Is this a common problem with an easy solution that I missed?
    – Nico Autia
    Commented Apr 19, 2020 at 9:17
  • looks like you've taking the install data directory from an incompatible instance. Look carefully at how each was created and what mysql version is in the container rather than the datadir.
    – danblack
    Commented Apr 19, 2020 at 9:33
  • 1
    Indeed changing the "mysql:5.7" to "mysql:8.0" (in my case) did the trick.
    – Nico Autia
    Commented Apr 19, 2020 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.