Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting secure_file_priv to local folder in MySQL 8.0 (Mac OSX)

Tags:

mysql

I am working on this portion of the MySQL tutorial for loading data from a .TSV file.

I have this data file:

pet_file

name    owner   species sex birth   death
Fluffy  Harold  cat f   1993-02-04  
Claws   Gwen    cat m   1994-03-17  
Buffy   Harold  dog f   1989-05-13  
Fang    Benny   dog m   1990-08-27  
Bowser  Diane   dog m   1979-08-31  1995-07-29
Chirpy  Gwen    bird    f   1998-09-11  
Whistler    Gwen    bird        1997-12-09  
Slim    Benny   snake   m   1996-04-29  

Stored in this location:

/Users/martinfrigaard/MySQLData/pet.txt

My first attempt used the following commands,

LOAD DATA INFILE '/pet.txt' INTO TABLE pet
LINES TERMINATED BY '\r';

and it brought the following error:

  ERROR 1148 (42000): The used command is not allowed with this MySQL version

After reading and searching the internet, I found an SO post on how to change the local_infile settings.

SET GLOBAL local_infile = true;
-- Query OK, 0 rows affected (0.00 sec)

And when I checked:

SHOW GLOBAL VARIABLES LIKE 'local_infile';

This looked like it worked.

  +---------------+-------+
  | Variable_name | Value |
  +---------------+-------+
  | local_infile  | ON    |
  +---------------+-------+
  1 row in set (0.00 sec)

But when I run the LOAD DATA file command again,

LOAD DATA INFILE '/pet.txt' INTO TABLE pet
LINES TERMINATED BY '\r';

it results in the following error.

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

Setting the GLOBAL secure-file-priv import settings?

I have adjusted the settings in the configuration file in three locations:

1.) As according to this post

mmbp:~ martinfrigaard$ cat ~/.my.cnf
[mysqld_safe]
[mysqld]
secure_file_priv="/Users/martinfrigaard/MySQLData"

2) According to this post

mmbp:~ martinfrigaard$ cat .my.cnf
[mysqld_safe]
[mysqld]
secure_file_priv="/Users/martinfrigaard/MySQLData"

3) And according to this post

GNU nano 2.9.8 /etc/my.cnf                                                                      

[mysqld]
[mysql]
secure-file-priv = "/Users/martinfrigaard/MySQLData"

But when I restart mysql and check the secure-file-priv settings,

mysql> SHOW VARIABLES LIKE 'secure_file_priv';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv | NULL  |
+------------------+-------+
1 row in set (0.00 sec)

I see this is still null. Any ideas on what else I am missing?

like image 974
Martin Frigaard Avatar asked Aug 24 '18 01:08

Martin Frigaard


1 Answers

Solution:

Directly edit the plist file: sudo nano /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

Add the line: <string>--secure-file-priv=/</string> to the file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Disabled</key>
        <false/>
        <key>ExitTimeOut</key>
        <integer>600</integer>
        <key>GroupName</key>
        <string>_mysql</string>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>com.oracle.oss.mysql.mysqld</string>
        <key>LaunchOnlyOnce</key>
        <false/>
        <key>ProcessType</key>
        <string>Interactive</string>
        <key>Program</key>
        <string>/usr/local/mysql/bin/mysqld</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/mysql/bin/mysqld</string>
                <string>--user=_mysql</string>
                <string>--basedir=/usr/local/mysql</string>
                <string>--datadir=/usr/local/mysql/data</string>
                <string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
                <string>--log-error=/usr/local/mysql/data/mysqld.local.err</string>
                <string>--pid-file=/usr/local/mysql/data/mysqld.local.pid</string>
                <string>--keyring-file-data=/usr/local/mysql/keyring/keyring</string>
                <string>--early-plugin-load=keyring_file=keyring_file.so</string>
                <string>--default_authentication_plugin=mysql_native_password</string>
                <string>--secure-file-priv=/</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>SessionCreate</key>
        <true/>
        <key>UserName</key>
        <string>_mysql</string>
        <key>WorkingDirectory</key>
        <string>/usr/local/mysql</string>
</dict>
</plist>

Worked for MySQL 8.0 using Sierra 10.13.6

like image 173
Minnow Avatar answered Oct 15 '22 00:10

Minnow