Can I create Trigger on mysql base [duplicate] - mysql

I am trying to audit the privilege changes in mysql.user table by writing a trigger on it.
insert trigger: will capture who gave the new permissions and when
update trigger: will capture who changes the privileges from what[old privilege]
remove trigger: will capture who removed the privileges and what are they
Now, I am getting an error while writing like
ERROR 1465 (HY000): Triggers can not be created on system tables
Can we create a trigger on system tables, Is there any work around or it will be supported in higher versions[> 5.1.61] ?
Thanks in advance.

No we can not. Even if we have the best concerned privileges are all and super
See (All) and (Super) Privileges Provided by mySql
After trying all type of privileges like
grant super on *.* to root#localhost
grant all on *.* to root#localhost
I have tried simplest trigger on different tables mysql.db and got same error
Triggers can not be created on system tables // Please accept this
bitter truth
If you found anywhere that triggers can be created on system tables, simply that is wrong

Had you seen this: http://forums.mysql.com/read.php?99,207145 ?
The poster says he needed "SUPER PREVILAGES"
Do you have access to the root user for the database?

Related

MySQL ERROR 1396 (HY000): Operation DROP USER failed for 'username'#'localhost'

The software im using automatically creates 2 mysql users during installation. Because of a slight issue those users were created wrongly and the Support advised me to remove the users form the database and then recreate them using the installer (theres a separate option to just create the database users).
The two users are 'username'#'localhost' and 'username'#'%' (yes, they have the same username on different hosts..)
My problem is that neither DROP USER 'username'#'localhost'; nor DROP USER 'username'#'%'; work, both throw an ERROR 1396.
My guess would be that it has to do with the user accounts "owning" elements in the database which would be orphaned. Is there a way to get past this and remove the users anyways? (Since they are gonna be recreated in a second?)
Clarification: Im using the mysql root user.
Ergest Basha's suggestion in this comment worked for me:
You could try deleting from mysql database. use mysql; then delete from user where user='username' and host ='localhost';

Why does SQL foribben to execute SELECT query?

I try to execute query in phpmyadmin and get error:
#1142 - SELECT command denied to user 'cpses_tkdpmnyjWW'#'localhost' for table 'user'
So, user cpses_tkdpmnyjWW'#'localhost is created dynamically and I can not set privileges for this user.
How to fix this?
Use SHOW GRANTS to show your current user privileges. It sounds as though the output may be similar to:
GRANT USAGE ON *.* TO 'Unnamed'#'localhost'
This would mean the account could sign into the server but do little else. This page gives a more detailed breakdown, as you'll see there are quite a few permutations.
The solution is you need to either find an account with more privileges or create/update one.
If the above is not an option, one quick trick I may try is connecting to '127.0.0.1' instead of 'localhost'. In MySQL the source of the connection can form part of the username so it's plausible that connecting on an IP instead of socket if you are on Unix flavoured OS.
Additionally, if you have admin/root access to the server, it is possible to create users when MySQL starts which is very useful in some scenarios.

Unable to create trigger on mysql system table [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
mysql: Cant we create triggers on system tables?
We are using MySQL ver 5.1.59 on rhel 6.1 (64 bit). We want to monitor the deletion of databases and for that trying to create a trigger on the db table of mysql database. We are creating the trigger by logging in as root user. the trigger written is as follows:
DELIMITER |
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER `mysql`.`test` BEFORE DELETE
ON `mysql`.`db`
FOR EACH ROW BEGIN
INSERT INTO cescnet.db_monitor (DB_name,user_name,dateandtime,operation_type) VALUES (mysql.db.Db,CURRENT_USER(),NOW(),'Delete');
END;|
But we are getting the error:
Error Code : 1465
Triggers can not be created on system tables
As we are working as root user, we think we have all the permissions on the system. The global privilege for root user from any host including local host includes the SUPER permission. Can anyone help us please?
I'm going to take a wild guess and say the reason you're getting that error message is that triggers can not be created on system tables.
Oh, perhaps I can add "regardless of privileges"
In short : You can not do.
I have also tried things like
See (All) and (Super) Privileges Provided by mySql
After trying all type of privileges like
grant super on *.* to root#localhost
grant all on *.* to root#localhost
I have tried simplest trigger and get same error
Triggers can not be created on system tables
If you found anywhere that triggers can be created on system tables, simply that is wrong

grant trigger to schema not working

I need to give an user TRIGGER permission for an whole schema in mysql to import mysql workbench backup.
I tried with:
grant trigger ON `schemaname`.* TO `user`#`localhost`
But while importing there comes the error that the user haven't the permissions.
ERROR 1142 (42000) at line 53: TRIGGER command denied to user 'user'#'localhost' for table 'table'
I tried to give the user TRIGGER permission to the table - that works, but of course only for that table, for the others still came the error.
Is there any way to give an user trigger permission to an schema without giving him the permission for every table separately?
From MySQL Docs
In MySQL 5.0 CREATE TRIGGER requires the SUPER privilege.
So you need to give SUPER privileges to the User. While importing, there will be command like "Create Trigger..." which is throwing an error.
Check your MySQL version and definer value as well for trigger in the importing file.
Edit:
For version 5.1, follow MySQL docs, that says:
CREATE TRIGGER requires the TRIGGER privilege for the table associated with the
trigger. The statement might also require the SUPER privilege, depending on
the DEFINER value, as described later in this section. If binary logging is
enabled, CREATE TRIGGER might require the SUPER privilege, as described in
Section 19.7, “Binary Logging of Stored Programs”. (Before MySQL 5.1.6, there is
no TRIGGER privilege and this statement requires the SUPER privilege in all cases)
The DEFINER clause determines the security context to be used when checking access
privileges at trigger activation time.
So, you need to check Definer value for importing trigger. It might have something like : DEFINER = root. Try removing the definer then try importing. Hope it works...
In MySQL docs:
To relax the preceding conditions on function creation (that you must have the
SUPER privilege and that a function must be declared deterministic or to not
modify data), set the global log_bin_trust_function_creators system variable
to 1. By default, this variable has a value of 0, but you can change it like
this:
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
You can also set this variable by using the
--log-bin-trust-function-creators=1
option when starting the server.
Set the global variable and reopened the session I was able to insert the trigger

#1142 - INSERT command denied to user ___ for table ___

Apparently this is usually to do with size, but I only have one table with six columns.
The only thing that has changed recently is that today I installed a forum but I've removed it again and the problem persists.
I am entering the SQL manually in PHPmyAdmin.
Any idea what the problem could be?
I just faced that ERROR, and found that my QUERY state incorrect spelled DATABASE name. :(
The problem is about the user session cookies, so all you need to do is to delete those cookies by clicking on the icon at the top right below phpMyAdmin as mentioned in this mage:
Your user doesn't have INSERT privilege. Check user database privileges.
Maybe you changed user, maybe you just changed the HOST or the IP from where you are connecting.
Use this statement to grant the privilege.
GRANT INSERT ON databaseName TO 'user'#'66.40.52.21'