patternsqlMinor
Updating mysql trigger via information_schema -- access denied?
Viewed 0 times
triggerupdatinginformation_schemadeniedmysqlviaaccess
Problem
I have some wrong "definer"s for some triggers in MySQL (actually MariaDB). I figured the easiest way of correcting them would be some version of:
It produces:
In the same session, I can drop and re-create the triggers with "drop trigger" and "create trigger", so I'm not understanding the permissions issue. Is there some privilege that my user needs that it doesn't have?
use information_schema;
update triggers set definer=current_user() where trigger_schema='foobar';It produces:
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'In the same session, I can drop and re-create the triggers with "drop trigger" and "create trigger", so I'm not understanding the permissions issue. Is there some privilege that my user needs that it doesn't have?
Solution
What you are doing is impossible because the INFORMATION_SCHEMA database is a database made up of in-memory read-only temporary tables (See my post How is INFORMATION_SCHEMA implemented in MySQL?)
You are going to have to drop the triggers and recreate them
I wrote a post on that before (
Here is what you can do for all triggers in the
STEP 01 : mysqldump the triggers
For clarification
STEP 02 : Create a script to drop all triggers
STEP 03 : Verify Contents of Each File
STEP 04 : Edit all the definers in
STEP 05 : Login to mysql and run this
Test this on a staging server please
GIVE IT A TRY !!!
You are going to have to drop the triggers and recreate them
I wrote a post on that before (
Oct 02, 2011 : Can mysqldump dump triggers and procedures?)Here is what you can do for all triggers in the
foo databaseSTEP 01 : mysqldump the triggers
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
mysqldump -${MYSQL_CONN} -d -t --skip-routines --triggers foo > foo_make_triggers.sqlFor clarification
- -d is the same as --no-data
- -t is the same as --no-create-info
STEP 02 : Create a script to drop all triggers
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQL="SELECT CONCAT('DROP TRIGGER ',trigger_name,';')"
SQL="${SQL} FROM information_schema.triggers"
SQL="${SQL} WHERE trigger_schema = 'foo'"
mysql ${MYSQL_CONN} -ANe"${SQL}" > foo_drop_triggers.sqlSTEP 03 : Verify Contents of Each File
vi -R foo_drop_triggers.sql
vi -R foo_make_triggers.sqlSTEP 04 : Edit all the definers in
foo_make_triggers.sql as you know howSTEP 05 : Login to mysql and run this
use foo
source foo_drop_triggers.sql
source foo_make_triggers.sqlTest this on a staging server please
GIVE IT A TRY !!!
Code Snippets
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
mysqldump -${MYSQL_CONN} -d -t --skip-routines --triggers foo > foo_make_triggers.sqlMYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQL="SELECT CONCAT('DROP TRIGGER ',trigger_name,';')"
SQL="${SQL} FROM information_schema.triggers"
SQL="${SQL} WHERE trigger_schema = 'foo'"
mysql ${MYSQL_CONN} -ANe"${SQL}" > foo_drop_triggers.sqlvi -R foo_drop_triggers.sql
vi -R foo_make_triggers.sqluse foo
source foo_drop_triggers.sql
source foo_make_triggers.sqlContext
StackExchange Database Administrators Q#78268, answer score: 6
Revisions (0)
No revisions yet.