How do I automatically execute a MySQL script or routine after forward engineering from model

痴心易碎 提交于 2019-12-07 06:54:05

问题


I've built a EER Model in MySQL Workbench that I forward engineer to create the database. The forward engineering works perfectly, and the database is created from the diagram as expected.

Apart from tables, there are also some Stored Procedures (aka Routines) that I've included in the model. These routines are designed to only be run once, as soon as the database has been set up. They automatically insert necessary data into the tables.

My question is, how can I get the forward engineering process to automatically call/execute one of these routines once the tables have been created.

At the moment, I have to forward engineer the database, and then manually call the stored procedures?


回答1:


In your EER diagram on the workbench right click on a table and select edit table. This will open n pane at the bottom with a couple of tabs. The tabs are table,columns,indexes,foreign key etc. There is a tab called insert. This tab allows you to insert records into the Model database.

When you click on the insert tab it will show a grid. Add the records you want to insert on this grid. Make sure you commit these records. See screen shot for a example

Now when you forward engineer the database on the very first screen there is a option to Generate insert statements. Tick the option forward engineer and the data you want inserted will be scripted when you create the model. Save the script so you can run it again and again without going into the MySQL workbench.

I have not found options to update,delete or do other data manipulation in the workbench but I think this is what you are looking for. NOTE To import the records You wont be able to do that via the workbench there is no option. You can save the records to file. However to import/create them you would need to add them one at a time (frm the modeller). You could however make a backup of the MySQL database with the records in already. Then copy those INSERT Statements from the MYSQL backup script into your setup script.

Steps would be:

  1. Create database.

  2. Import the files with the setup/config records into newly created database

  3. Backup database

  4. Open backup file copy and paste the INSERT statements you are looking for into the setup script created by the MySQL Workbench

UPDATE:

I did some experimenting when you get to the review script to be executed step in the forward engineering you can also at the end call the stored procedures(as you mentioned) by editing the script. Once done save the script to file and test.

Hope that helps!



来源:https://stackoverflow.com/questions/10384659/how-do-i-automatically-execute-a-mysql-script-or-routine-after-forward-engineeri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!