中止MySQL脚本执行的方式(也许提高错误)? [英] Way to abort execution of MySQL scripts (raising error perhaps)?

查看:289
本文介绍了中止MySQL脚本执行的方式(也许提高错误)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为MySQL编写安装脚本(通常使用mysql控制台的'source [file]'),这部分取决于现有的数据,而且环境有差异,这意味着有时脚本失败。一个常见的情况是,带有select(定位一个id)的'SET'语句找不到任何东西;控制台将值设置为NULL。在这种情况下,我希望脚本失败;我听说这会通过提高错误(与其他DB)来完成。但是,似乎MySQL没有办法做到这一点。

I need to write setup scripts for MySQL (usually run using 'source [file]' from mysql console) that depend partly on existing data, and there are differences in environments, meaning that sometimes script does fail. A common case is that a 'SET' statement with a select (to locate an id) fails to find anything; console sets value to NULL. In this case I would like the script to fail; I have heard this would be done by raising an error (with other DBs). However it appears like MySQL didn't have a way to do this.

在这种情况下是否有很好的方法强制失败?因为现在更新会在插入尝试使用null时失败,但即使这样也不会终止脚本本身。理想情况下,只要遇到问题,就会失败并终止。

Are there good ways to force failure under such conditions? As things are now updates will fail when insert tries to use null, but even that does not terminate script itself. Ideally it would just fail and terminate as soon as a problem is encountered.

推荐答案

我想你遇到的是一个限制的MySQL控制台。给出一个语句列表,MySQL控制台执行每一个,无论生成什么错误。即使您实施了以前的评论提到的一些提问建议,MySQL控制台也不会在遇到这样的错误时停止执行。

I think what you're encountering is a limitation of the MySQL console. Given a list of statements, the MySQL console executes each one regardless of any errors generated. Even if you implemented some of the error-raising suggestions that previous comments have mentioned, the MySQL console won't stop executing when such an error is encountered.

假设您没有资源将脚本语言应用于可能为您执行SQL并处理错误的问题。我认为在这种情况下,您只需要比MySQL控制台更强大的工具。

I'll assume that you don't have the resources to apply a scripting language to the problem that could execute your SQL for you and handle the errors. I think in this case, you just need a more robust tool than the MySQL console.

MySQL管理员如果我正确地了解你的问题,你需要做什么。如果您设置了MySQL连接并连接到数据库,则可以从工具菜单中使用两种工具。正常的MySQL控制台在那里,但是你也有MySQL查询浏览器。

MySQL Administrator does what you need, if I understand your problem correctly. If you set up your MySQL connection and connect to the database, you have two tools available from the Tools menu. The normal MySQL console is there, but you also have the MySQL Query Browser.

如果打开查询浏览器,你将获得一个您的MySQL数据库的一个不错的GUI视图。文件 - >打开脚本以打开您的SQL脚本,然后使用执行按钮。

If you open the Query Browser, you get a decent GUI view of your MySQL databases. File -> Open Script to open your SQL script, then use the Execute button.

您会得到一个不错的进度条,更重要的是从它的声音,如果查询失败,脚本执行停止并突出显示失败的查询。您可以选择跳过并继续进行,甚至可以手动修改数据,并从脚本之外的其他位置启动。

You get a nice progress bar, and more importantly from the sounds of it, if a query fails, the script execution halts and highlights the failed query. You can choose to skip it and keep going, or even manually modify your data and start up from someplace else farther down the script.

我几乎立即放弃了MySQL控制台我发现了并尝试过管理员。

I abandoned the MySQL console almost immediately once I found out about and tried Administrator.

这篇关于中止MySQL脚本执行的方式(也许提高错误)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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