1
0

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 1 year has passed since last update.

MySQL8でストアドファンクションを登録できない問題

Posted at

はじめに

MySQL5系からMySQL8.0にアップデートした時、ストアドファンクションを登録できなくなったので、解消方法をまとめます。

問題

エラー内容

Mysql2::Error: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)

# 翻訳
# SUPER 権限がなく、バイナリ ロギングが有効になっています (安全性の低い log_bin_trust_function_creators 変数を使用することもできます)

解決方法

mysqlの設定のlog_bin_trust_function_creatorsの値がOFFだと上記のエラーが出ます。

SHOW variables like 'log_bin_trust_function_creators';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF   |
+---------------------------------+-------+

関数を作成するには、ユーザーがSUPER権限を持っている必要があるため、今回エラーが出ていた模様。

ストアドファンクションを作成または変更するには、通常必要なCREATE ROUTINEまたはALTER ROUTINE権限に加えて、SET_USER_ID権限 (または非推奨のSUPER権限)が必要です。
関数作成に関する前述の条件(SUPER権限を持つ必要があることと、関数が決定的であるか、データを変更しないと宣言する必要があること)を緩和するには、log_bin_trust_function_creators グローバルシステム変数を1に設定します。デフォルトでこの変数には0の値が設定されていますが、次のように変更できます。
mysql> SET GLOBAL log_bin_trust_function_creators = 1;

以下のコマンドを使ってlog_bin_trust_function_creatorsの値をONにすることで、ストアドファンクションの登録ができるようになります。

SET GLOBAL log_bin_trust_function_creators = 1;
SHOW variables like 'log_bin_trust_function_creators';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | ON    |
+---------------------------------+-------+

参考

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?