Skip to content
Home » MySQL » How to Resolve ERROR 1359 (HY000): Trigger already exists

How to Resolve ERROR 1359 (HY000): Trigger already exists

Let's reproduce the error.
mysql> use db1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create trigger xxx before insert on posts for each row begin end;
ERROR 1359 (HY000): Trigger already exists

The errors show there's a name conflict of this trigger xxx. I know you had never created a trigger named xxx in the same table. But I think you had ever created a trigger xxx in the same database. This is because "Trigger" in MySQL shares the same namespace per database basis. Next, let me show you why.

Switch to the location of the database db1.
[root@test ~]# cd /var/lib/mysql/db1/
[root@test db1]#

It means that one database occupies one directory to store entities.

List all the files related to xxx in the database.
[root@test db1]# ll xxx*
-rw-rw---- 1 mysql mysql 42 Jun 14 04:57 xxx.TRN

As you can see, one trigger one file. Is there any way to create the same name file in the same directory? The answer is no.

That's why you cannot create a duplicate named trigger in the same database.

Leave a Reply

Your email address will not be published. Required fields are marked *