从模型进行正向工程后,如何自动执行MySQL脚本或例程 [英] How do I automatically execute a MySQL script or routine after forward engineering from model

查看:143
本文介绍了从模型进行正向工程后,如何自动执行MySQL脚本或例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在MySQL Workbench中建立了EER模型,我将其转发给工程师以创建数据库.正向工程完美地工作,并且按预期从该图创建了数据库.

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?

推荐答案

在工作台上的EER图中,右键单击一个表,然后选择编辑"表.这将在底部打开带有两个选项卡的n窗格.选项卡是表格,列,索引,外键等.有一个称为插入的选项卡.此选项卡允许您将记录插入到Model数据库中.

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

现在,当您在第一个屏幕上对数据库进行正向工程设计时,将提供一个生成插入语句的选项.勾选选项正向工程师,您要插入的数据将在创建模型时编写脚本.保存该脚本,以便您可以一次又一次地运行它,而无需进入MySQL工作台.

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.

我在工作台中没有找到更新,删除或执行其他数据操作的选项,但是我认为这是您想要的.注意要导入记录,您将无法通过工作台执行此操作,没有任何选择.您可以将记录保存到文件.但是,要导入/创建它们,您需要一次添加一个(从建模者那里).但是,您可以备份已包含记录的MySQL数据库.然后将那些INSERT语句从MYSQL备份脚本复制到安装脚本中.

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.

步骤如下:

  1. 创建数据库.

  1. Create database.

将带有设置/配置记录的文件导入到新创建的数据库中

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

备份数据库

打开备份文件副本,然后将要查找的INSERT语句粘贴到MySQL Workbench创建的安装脚本中

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

更新:

当您进行正向工程中的审阅脚本步骤时,我做了一些实验,最后您还可以通过编辑脚本来调用存储过程(如您所述).完成后,将脚本保存到文件并进行测试.

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.

希望有帮助!

这篇关于从模型进行正向工程后,如何自动执行MySQL脚本或例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆