1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【MySQL】MySQLでCSVファイルを読み込もうとした時に、--secure-file-priveエラーが発生した時の対処法

Posted at

エラー内容

LOAD DATA INFILEコマンドでCSVファイルを読み込もうとしたら下記エラーが発生する。

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

開発環境

OS:Mac M1(BigSur11.5.2)
MySQL:5.7.34

解決法

secure-file-priv optionの設定を確認。

mysql> SELECT @@global.secure_file_priv; 
 
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
| NULL                      |
+---------------------------+

ここがNULLなのが良くないらしいです。
修正するためにはmy.cnfファイルの編集が必要ですが、MySQLのバージョンによって設定方法が異なります。

MySQLのバージョンを確認。

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.34    |
+-----------+

5.7以降:自身でmy.cnfファイルを新規作成&設配置する必要があります。

ファイルパス

/MAMP/conf/my.conf

image.png

ファイルに記載する内容

[mysqld]
secure-file-priv = ""

配置できたら**「MySQLを再起動」**すること。
(MAMP右上の"stop"→"start"を押せばOK)
image.png

再度設定を確認すると、NULLがなくなりました!

mysql> SELECT @@global.secure_file_priv;   
+---------------------------+
| @@global.secure_file_priv |
+---------------------------+
|                           |
+---------------------------+

LOAD DATA INFILEコマンドも無事実行できました。

参考:【MYSQL】データをエクスポートしようとしたらsecure-file-privがどうのこうのって言われたときの対処法
参考:MAMP(MacOS)でのmy.cnfファイルの作成方法

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?