【问题标题】:Setting secure_file_priv to local folder in MySQL 8.0 (Mac OSX)在 MySQL 8.0 (Mac OSX) 中将 secure_file_priv 设置为本地文件夹
【发布时间】:2019-01-30 11:00:53
【问题描述】:

我正在研究 MySQL 教程的 this portion,用于从 .TSV 文件加载数据。

我有这个数据文件:

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  

存储在这个位置:

/Users/martinfrigaard/MySQLData/pet.txt

我的第一次尝试使用了以下命令,

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

它带来了以下错误:

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

在阅读和搜索互联网后,我找到了一个SO post,关于如何更改local_infile 设置。

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

当我检查时:

SHOW GLOBAL VARIABLES LIKE 'local_infile';

这看起来很有效。

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

但是当我再次运行LOAD DATA文件命令时,

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

它会导致以下错误。

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

正在设置GLOBAL secure-file-priv 导入设置?

我在三个位置调整了配置文件中的设置:

1.) 根据这个post

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

2)据此post

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

3) 并据此post

GNU nano 2.9.8 /etc/my.cnf                                                                      

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

但是当我重新启动mysql并检查secure-file-priv设置时,

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

我看到这仍然是空的。关于我还缺少什么的任何想法?

【问题讨论】:

  • 我也遇到了同样的问题

标签: mysql


【解决方案1】:

解决方案

直接编辑plist文件: sudo nano /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

将行:<string>--secure-file-priv=/</string> 添加到文件中:

<?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>

使用 Sierra 10.13.6 为 MySQL 8.0 工作

【讨论】:

  • 这在 Catlina 上对我有用,但我必须先使用 sudo plutil -convert xml1 /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist 将 .plist 文件转换为 XML
猜你喜欢
  • 2019-08-06
  • 2021-03-16
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-11
  • 2021-07-18
相关资源
最近更新 更多