mysql脚本中的IF条件 [英] IF condition in mysql script

查看:106
本文介绍了mysql脚本中的IF条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本来修补我们的mysql数据库。我可以运行这样的东西:

I am trying to write a script to patch our mysql database. Something like this I can run:

If IsTargetVersion(1.1) 
THEN
ALTER TABLE t1 ENGINE = InnoDB;
END IF;

我发现有关MySql的有趣之处是:它不支持脚本中的条件。我不想创建存储过程,调用它并将其放入我的脚本中。这看起来很愚蠢...

The funny thing I found about MySql is: it doesn't support if condition in script. I don't want to create a store procedure, call it and drop it in my script. That looks stupid...

有没有人有更好的方法?

Does anybody have better approach?

谢谢

推荐答案

此(模式)解决方案只是一种解决方法,可以帮助您在MySQL脚本中使用IF条件 -

This (pattern) solution just a workaround which will help you to use IF condition in the MySQL scripts -

SET @s = IF(IsTargetVersion(1.1), 'ALTER TABLE t1 ENGINE = InnoDB', 'DO SLEEP(0)');
PREPARE stmt1 FROM @s;
EXECUTE stmt1;

这篇关于mysql脚本中的IF条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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