Home > Database > Mysql Tutorial > How to Fix MySQL Error 1290 (HY000): The --secure-file-priv Issue

How to Fix MySQL Error 1290 (HY000): The --secure-file-priv Issue

Susan Sarandon
Release: 2024-10-29 10:04:30
Original
1063 people have browsed it

How to Fix MySQL Error 1290 (HY000): The --secure-file-priv Issue

Error 1290 (HY000): Solving the --secure-file-priv Issue

MySQL error 1290 (HY000), often encountered when attempting to write query results to a text file, is caused by MySQL's --secure-file-priv option. This option restricts the server from writing files to arbitrary locations.

Ubuntu 16.04:

To resolve this issue in Ubuntu 16.04, determine the allowed write directory using the following command:

mysql> SELECT @@GLOBAL.secure_file_priv;
Copy after login
Copy after login
Copy after login

Write to the specified directory as follows:

mysql> SELECT * FROM train INTO OUTFILE '/var/lib/mysql-files/test.csv' FIELDS TERMINATED BY ',';
Copy after login

Mac OSX (MAMP Installation):

  1. Check the allowed write directory:
mysql> SELECT @@GLOBAL.secure_file_priv;
Copy after login
Copy after login
Copy after login

If the result is NULL, create a file named '~/.my.cnf' and add the following lines:

[mysqld_safe]
[mysqld]
secure_file_priv="/Users/username/"
Copy after login
  1. Replace 'username' with your user directory.
  2. Restart the MySQL server via MAMP.
  3. Verify the change:
mysql> SELECT @@GLOBAL.secure_file_priv;
Copy after login
Copy after login
Copy after login
  1. Export the table:
mysql> SELECT * FROM train INTO OUTFILE '/Users/username/test.csv' FIELDS TERMINATED BY ',';
Copy after login

By following these steps, you can disable the --secure-file-priv restriction and write query results to specified text files on your system.

The above is the detailed content of How to Fix MySQL Error 1290 (HY000): The --secure-file-priv Issue. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template