Although this post is quite old, in 2018 this problem is still there. I spent a couple of hours banging my head in this maze.
Server version: 5.7.24 MySQL Community Server (GPL) running on Ubuntu 14.04
To allow MySql to SELECT INTO OUTFILE requires to set MySQL's secure-file-priv
option in your configuration.
Append the following 2 lines to /etc/mysql/mysql.conf
:
[mysqld]
# allow INTO OUTFILE file and LOAD DATA INFILE to this directory
secure_file_priv=/usr/share/mysql-files
/usr/share/mysql-files
is the directory where my files will be stored. I created it doing:
sudo su
cd /usr/share
mkdir mysql-files
chown mysql:mysql mysql-files
chmod a+rw mysql-files
Change /usr/share/mysql-files
for whatever you prefer, but avoid to use the /tmp
directory!
Why?
Because, at next time you'll be rebooting, the /tmp
directory is happily erased including your precious mysql-files sub-directory. The mysql service then chokes and it won't start, leading to wierd errors with cryptics messages.
restart mysql and check:
sudo su
service mysql restart
mysql
mysql> SHOW VARIABLES LIKE "%secure%";
+--------------------------+-------------------------+
| Variable_name | Value |
+--------------------------+-------------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /usr/share/mysql-files/ |
+--------------------------+-------------------------+
3 rows in set (0.07 sec)
mysql> quit
Bye
You are not done, yet!
There is a troll by the name of apparmor
who will ruines your project.
Edit the file /etc/apparmor/local/usr/sbin/mysqld
and append the
following 2 lines -- don't forget the ending commas:
/usr/share/mysql-files rw,
/usr/share/mysql-files/** rw,
save it, and reparse:
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
That should make it.
p1.txt
already exist (it shouldn't)? Does the user under which themysqld
process have permission to write to the/var/www
directory? – Miliary