0

(not all details should be relevant; however writing all valuable information on database might help with the solution) I am trying to write a mariaDB database on manjaro where there is a table that upon the addition of a row it will add a user with details according to that row, and upon deletion will remove said user.

DELIMITER $$
$$
CREATE TRIGGER user_creation
AFTER INSERT ON Users FOR EACH ROW
BEGIN 
   DECLARE username CHAR(100);
   DECLARE password_hash CHAR(100); 
   SELECT NEW.user_name INTO username; 
   SELECT NEW.hash INTO password_hash; 
   CREATE USER username@'%' IDENTIFIED BY password_hash [AS 'auth_string'];
   GRANT SELECT TO username@'%';
END;$$
DELIMITER ;

I looked through the results for this question because it seemed right for me but I couldn't get it to work.

ORACLE PLSQL Create user with trigger identified by :new username and password

  • what do you want to do – Hirumina Apr 03 '20 at 06:14
  • create a table that is synchronized and can be referred to by foreign keys from the database users that adds and drops users – Cecil Hammett Apr 03 '20 at 06:22
  • 1
    I do NOT recommend you to solve your task by thigger. Realize new user creation/insertion as stored procedure, in which you may easily perform any operations pack - insert into `your_database`.`users`, create according MySQL account, grant needed privileges... even revert (emulate rollback) if error occures. – Akina Apr 03 '20 at 06:55

0 Answers0