Create mysql user in Trigger

Asked

Viewed 41 times

0

I need that after being registered a new person in the table Trigger be fired and create a new user in the database with the data name and password of the registered record. I tried with several models of insruções but I did not succeed, tried the common way to create a new user:

delimiter $
create trigger tgr_new_user after insert on pessoa
for each row
begin
    create user new.nome@'localhost' identified by new.senha;
end $
delimiter ;

but Mysql returns error.

  • 1

    "but Mysql returns error" which error? put in question the details

1 answer

1

Cannot execute some commands like CREATE USER inside a Rigger house. Here is a list (in English) of some restrictions: stored-program-Restrictions.html

To create a new user you will need to insert directly into the user table of MySQL, which is the table mysql.user: mysqluser-table

The command would look like this:

INSERT INTO mysql.user (host, user, password)
VALUES ('localhost',new.nome, new.senha);
  • In this case he creates Trigger, but when inserting a new registration in the entity he error in the execution of Trigger "Error Code: 1054. Unknown column 'password' in 'field list' I am using Mysql 8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.