0

I am very new with SQL but I have to extract some fields of a table stored in a sql file.

I have installed mysql and create the database and source the file. Now I wanted to execute a sql request in order to read all the elts of the table, extract the interesting fields and write them into cvs file:

SELECT * INTO OUTFILE '/home/cr/database/Dump2/program_info.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM program_info;

When running the command I have the following error message:

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

Does anyone knows how to solve it ? I have struggled with this message all the afternoon but could not .

I am working on Linux ubuntu and my config file is /etc/my.cfg

[mysqld] read-only = 0 secure-file-priv = ""

Thank you for your help

5
  • check the mysqld command line. just because the directive isn't in the .ini/.cnf file doesn't mean it can't be specified elsewhere. Commented Jul 13, 2016 at 14:33
  • How do I "check the mysqld" ? BR Commented Jul 13, 2016 at 14:49
  • ps auxwww|grep mysqld Commented Jul 13, 2016 at 14:50
  • Thank you, running your command I have the following output: mysql 29141 0.1 1.1 1915592 183236 ? Ssl 16:51 0:00 /usr/sbin/mysqld Commented Jul 13, 2016 at 14:55
  • What version of MySQL are you using ? Commented Jul 13, 2016 at 15:46

1 Answer 1

3

MySQL is actually working as intended. The MySQL server booted with the --secure-file-priv option which basically restricts you from saving output into random directories. You need to check the startup parameters.

To do so, run the following command in the MySQL shell:

SHOW VARIABLES LIKE 'secure_file_priv';

The output would be what the MySQL Server currently thinks is the permitted location. You should be able to save your output to this location.

To disable the restriction, you need to edit the configuration file that declares it and restart the MySQL Server after changing the option.

MySQL could be reading the my.ini (or my.cnf) configuration file from a variety of locations. See Using Option Files for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

My files are outputting to the secure_file_priv location, but is it possible to put 2 subfolders in that directory and have it output to those? Currently it gives me a "permission denied" message but I'm not sure if there is a workaround so that I can export 2 different data sets to 2 locations, as they are ultimately still inside the secure_file_priv directory.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.