Rishi Jasapara
Rishi Jasapara

Reputation: 638

create tables in all newly created databases in MySQL

On each new registration, I create a database for each user using PHP. Each database has a set of 8 tables. So I simply want to create those 8 tables for each new user or let's say each time a new database is created.

I cannot use triggers because they can be used only on tables. What else can be done here? Is there something very simple that I am missing?

Update: I just found that there are stored procedures as well. Can these stored procedures be used like triggers to check for new database creation and execute?

Upvotes: 0

Views: 53

Answers (2)

mogul
mogul

Reputation: 4553

Make yourself a control database, with a table, call it db_list. Put a trigger on that table to do your housekeeping. (create customer database and setting up grants)

Upvotes: 1

Kendrick
Kendrick

Reputation: 3787

Run the creation scripts after you create the dataabase. I'm not aware of a "default tables" option in MySQL, as that functionality is easy to replicate and would be very rarely used.

Upvotes: 1

Related Questions