Determine secure-file-priv variable path in MySQL with these 2 commands.

Potentially, when running LOAD DATA INFILE or SELECT INTO OUTFILE commands in MySQL, you may be faced with a --secure-file-priv error… So what does this error mean in reference to reading and writing files? What location can you write to or load data from on your server? This blog post will show 2 easy commands to determine the location according to your install…


structured-rows-of-numbers

Photo by Mika Baumeister on Unsplash

Note: All data, names or naming found within the database presented in this post, are strictly used for practice, learning, instruction, and testing purposes. It by no means depicts actual data belonging to or being used by any party or organization.
OS and DB used:

  • Xubuntu Linux 16.04.5 LTS (Xenial Xerus)
  • MySQL 5.7.23

Below is the error covered in this post:

1
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

Let’s visit the secure_file_priv documentation exact definition to find out what it is used for.

This variable is used to limit the effect of data import and export operations, such as those performed by the LOAD DATA and SELECT … INTO OUTFILE statements and the LOAD_FILE() function. These operations are permitted only to users who have the FILE privilege.

Below is my summary of the available setting options. However, be sure and visit the link above for exact definitions:

  • Although not considered secure, it can be set to empty, resulting in no effect.
  • If set to the name of a directory it must: 1) Already exist, 2) Only imports and/or exports are allowed to or from the set directory.
  • All imports and exports can be disabled completely, via setting to the NULL value.
So what directory can I import/export from?

You can solve the mystery file location by issuing either of the below commands:

1
2
3
4
5
6
7
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.01 sec)
1
2
3
4
5
6
7
mysql> SELECT @@global.secure_file_priv;
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/     |
+---------------------------+
1 row in set (0.00 sec)

An Important Note: Only alter and set the variable to your desired path or leave as the default (if that is your wish) according to your requirements(s) and/or best practices. The blog post demo presented here, is a local learning/development environment and is not used in nor production quality/ready.

Like what you have read? See anything incorrect? Please comment below and thanks for reading!!!

Explore the official MySQL 5.7 Online Manual for more information.

A Call To Action!

Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.

Visit the Portfolio-Projects page to see blog post/technical writing I have completed for clients.

Have I mentioned how much I love a cup of coffee?!?!

To receive email notifications (Never Spam) from this blog (“Digital Owl’s Prose”) for the latest blog posts as they are published, please subscribe (of your own volition) by clicking the ‘Click To Subscribe!’ button in the sidebar on the homepage! (Feel free at any time to review the Digital Owl’s Prose Privacy Policy Page for any questions you may have about: email updates, opt-in, opt-out, contact forms, etc…)

Be sure and visit the “Best Of” page for a collection of my best blog posts.


Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.

Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, are performed on a personal development/learning workstation-environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.

Hey thanks for commenting! Leave a Reply

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