REFERENCES権限
https://dev.mysql.com/doc/refman/5.6/ja/privileges-provided.html
僕はこれを見てすっかり誤認していました。
REFERENCES 権限は現在使用されていません。
あー、過去にはあったけど使ってないのね。じゃあ、いらないよね→REVOKE。
と。
テーブルができない問題発生
実際にテーブル作成しようとしてみると、確かにhogeuserユーザでテーブルが作成できない。
mysql> SELECT * FROM mysql.user where user='hogeuser'\G
*************************** 1. row ***************************
Host: %
User: hogeuser
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y ←テーブル作成権限はここ
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: N
Process_priv: Y
File_priv: N
Grant_priv: N
References_priv: N ←問題はここ
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: N
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *********************************
password_expired: N
password_last_changed: 2018-11-26 14:30:00
password_lifetime: NULL
account_locked: N
1 row in set (0.35 sec)
テーブルを作成する権限はある。
mysql> CREATE TABLE `hogehoge` (
-> `hogehoge_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ほげほげID',
-> `hogerin_id` bigint(20) NOT NULL COMMENT 'ほげりんID',
-> ・・・
-> PRIMARY KEY (`hogehoge_id`),
-> KEY `f_hogehoge` (`hogerin_id`),
-> CONSTRAINT `f_hogehoge` FOREIGN KEY (`hogerin_id`) REFERENCES `hogerin` (`hogerin_id`) ON DELETE CASCADE ON UPDATE CASCADE
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='ほげほげ情報';
ERROR 1142 (42000): コマンド REFERENCES は ユーザー 'hogeuser'@'xxx.xxx.xxx.xxx' の表 'hogerin' の使用に関して許可されていません。
mysql>
※テーブル名等はぼかしてます。
マニュアル一通り見直してみると、
MySQL5.5
https://dev.mysql.com/doc/refman/5.5/en/privileges-provided.html#priv_references
・REFERENCES This privilege is unused before MySQL 5.5.41. As of 5.5.41, creation of a foreign key constraint requires at least one of the SELECT, INSERT, UPDATE, > DELETE, or REFERENCES privileges for the parent table.
MySQL5.6
https://dev.mysql.com/doc/refman/5.6/en/privileges-provided.html#priv_references
・REFERENCES This privilege is unused before MySQL 5.6.22. As of 5.6.22, creation of a foreign key constraint requires at least one of the SELECT, INSERT, UPDATE, > DELETE, or REFERENCES privileges for the parent table.
MySQL5.6日本語
https://dev.mysql.com/doc/refman/5.6/ja/privileges-provided.html#priv_references
REFERENCES 権限は現在使用されていません。
MySQL5.7
https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_references
・REFERENCES Creation of a foreign key constraint requires the REFERENCES privilege for the parent table.
MySQL8.0
https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_references
・REFERENCES Creation of a foreign key constraint requires the REFERENCES privilege for the parent table.
REFERENCES権限、むしろMySQL5.7から必要やん!
日本語だけニュアンス違う!
かつ、最近のバージョンであればMySQL5.5や5.6にも適用されている。
不幸中の幸いでこのユーザ作った後、FKと絡んだDDLが本番作業でなかったので事なきを得ました。
MySQLのマニュアルの怖さを知りました。
今後は使ってるバージョンのやつを必ず見るようにします。
(バグレポ出そうか、迷う・・・。)