patternsqlMajor
What's the minimum privilege needed to alter a foreign key constraint?
Viewed 0 times
theneededprivilegewhatminimumforeignconstraintalterkey
Problem
What's the minimum privilege needed to alter a foreign key constraint?
My migration script stopped working after MySQL 5.5.41 fixed this bug:
I get this error:
SQLSTATE[42000]: Syntax error or access violation: 1142 REFERENCES command denied to user 'foo'@'localhost' for table 'core.users' (SQL: alter table
Which means I need to fix the privileges. What's the minimum privilege I need?
My migration script stopped working after MySQL 5.5.41 fixed this bug:
- InnoDB permitted a foreign key to be created which referenced a parent table for which the user did not have sufficient privileges. (Bug #18790730)
I get this error:
SQLSTATE[42000]: Syntax error or access violation: 1142 REFERENCES command denied to user 'foo'@'localhost' for table 'core.users' (SQL: alter table
user_baz add constraint user_baz_user_id_foreign foreign key (user_id) references core.users (id) on delete cascade on update cascade)Which means I need to fix the privileges. What's the minimum privilege I need?
Solution
GRANT [type of permission] ON [database name].[table name] TO '[username]'@'[host name or IP address]';For example:
GRANT REFERENCES ON test.user_baz TO 'foo'@'localhost';Code Snippets
GRANT [type of permission] ON [database name].[table name] TO '[username]'@'[host name or IP address]';GRANT REFERENCES ON test.user_baz TO 'foo'@'localhost';Context
StackExchange Database Administrators Q#90800, answer score: 20
Revisions (0)
No revisions yet.