9
6

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 5 years have passed since last update.

MySQL5.7で secure-file-priv が効いてファイル保存できない場合の対処法(windows環境)

Last updated at Posted at 2018-01-28

MySQL 5.7 のデータをCSVファイルなどに保存したいときに「The MySQL server is running with the --secure-file-priv option so it cannot execute this statement」と出てファイル保存できない場合の対処法
(Windows環境を例に説明します)

テーブル内容をファイルに書き出す

testテーブルの内容を c:/temp/test.txt に保存しようとすると、

mysql> SELECT * FROM test INTO OUTFILE 'c:/temp/test.txt';

以下のようなメッセージが出て、ファイル出力に失敗したときの対処法

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

my.iniを開いて、secure-file-priv を無効にする

my.iniはデフォルトのインストール状態だと
C:\ProgramData\MySQL\MySQL Server 5.7にある。

image.png

以下のようにmy.iniを編集して**secure-file-priv=""**にする

image.png

MySQLを再起動する

まず、前提としてMySQL 5.7がWindowsサービスとして起動している環境を想定

1.管理者権限でコマンドプロンプトを起動する

2.MySQL 5.7のbinフォルダに移動する

cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"

3.MySQL 5.7をshutdownする

(rootのパスワードは仮に"password"とする)

mysqladmin -u root shutdown -ppassword

これにより、MySQLサービスも STOPPED ステートになる

4.MySQL 5.7を起動する

MySQLサービスを起動する

NET START MYSQL57

実行結果
image.png

テーブル内容をファイルに書き出す(リトライ)

mysql> SELECT * FROM exchange INTO OUTFILE 'c:/temp/test.txt';
Query OK, 86 rows affected (0.00 sec)

今度は無事成功!

9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?