Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions for creating a trigger in mysql

Tags:

mysql

triggers

mysql ver is 5.0.67

my trigger code is :

DELIMITER //
CREATE TRIGGER upd_price BEFORE UPDATE ON product_price
 FOR EACH ROW BEGIN  
    INSERT INTO update_price_log (product_id, product_price_old, product_price_new) values(OLD.product_id, OLD.product_price, NEW.product_price);
END
//
DELIMITER ;

error is:

#1227 - Access denied; you need the SUPER privilege for this operation

my server, is not cpanel! it is : DirectAdmin Web Control Panel.

how can i create SUPER privilege and create my trigger?

like image 349
Mohammad Mirzadeh Avatar asked Sep 10 '09 08:09

Mohammad Mirzadeh


People also ask

How do I grant trigger privileges in MySQL?

To do this, issue the following command in your MySQL client: GRANT TRIGGER ON <mahara_db_name>. * TO '<mahara_db_user>'@'localhost'; Replace <mahara_db_name> with the name of your Mahara database, and <mahara_db_user> with the database user.

Can we create trigger in MySQL?

To create a trigger or drop a trigger, use the CREATE TRIGGER or DROP TRIGGER statement, described in Section 13.1. 22, “CREATE TRIGGER Statement”, and Section 13.1. 34, “DROP TRIGGER Statement”. Here is a simple example that associates a trigger with a table, to activate for INSERT operations.

What are the privileges in MySQL?

Privileges for database objects such as tables, indexes, views, and stored routines can be granted for specific objects within a database, for all objects of a given type within a database (for example, all tables in a database), or globally for all objects of a given type in all databases.

How permissions are implemented in MySQL?

In MySQL, the user permissions are granted to the MySQL user account which determines operations that can be performed in the server. These user permissions may differ in the levels of privileges in which they are applied for several query executions.


2 Answers

Another way to create trigger without SUPER privilege by adding the following line to my.cnf or my.ini log_bin_trust_function_creators = 1

like image 101
alkree Avatar answered Nov 08 '22 00:11

alkree


I tried to give SUPER privilede on database.table level, but it fails, so I did

grant super on *.* to 'my_user'@'localhost';

then created my triggers. But don't forget to revoke it

revoke super on *.* from 'my_user'@'localhost';

Because it's a dangerous privilege to leave it granted in internet database

like image 40
Jeff_Alieffson Avatar answered Nov 07 '22 23:11

Jeff_Alieffson