将SQL粘贴到MySQL命令行中 [英] Pasting SQL into the MySQL command line

查看:251
本文介绍了将SQL粘贴到MySQL命令行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义一些SQL代码的应用程序:

I have an application that is defining some SQL code:

mySql = "SELECT     
            sq.question, 
            qs.title, 
            sq.id as question_id, 
            sq.type,
            qs.id as option_id, 
            sri.title as rankTitle,
            sri.id as rankId,
            sfi.title as formTitle,
            sfi.id as formId,
            sq.sub_type,
            sq.sort_order
FROM        survey_questions as sq 
LEFT JOIN   question_suboptions as qs
ON          sq.id = qs.question_id 
LEFT JOIN   survey_rankingitems as sri
ON          sq.id = sri.question_id
LEFT JOIN   survey_formitems as sfi
ON          sq.id = sfi.question_id
WHERE       sq.survey_id = #{@surveyId}
ORDER BY    sq.sort_order"

我想将此代码(双引号之间的所有内容)粘贴到MySQL命令行中,更改一个参数并执行它,但是我遇到了一个问题,其中MySQL上方的每一行都会显示:

I would like to paste this code (everything between the double quotes) in the MySQL command line, change the one parameter and execute it, but I have run into an issue where for every line above MySQL will display:

显示所有1450种可能性? (是或否)

Display all 1450 possibilities? (y or n)

然后输入1450个不同的可用命令.如果删除所有换行符和制表符,则可以粘贴,但这既费时又痛苦.我可以简单地粘贴上面的代码,对其进行编辑,然后将其作为一个单元执行吗?

And then 1450 different available commands. If I remove all linebreaks and tabs then I can paste in, but that is time consuming and a pain. Is there a way that I can simply paste in the above code, edit it and then execute it as a single unit?

推荐答案

也许您可以将语句保存到文本文件myTest.sql,然后使用MySQL命令source myTest.sql运行它?然后,您可以调整文件中的SQL,保存更改,然后再次运行.

Perhaps you could save the statement to a text file myTest.sql, then use the MySQL command source myTest.sql to run it? You could then tweak the SQL in the file, save the changes, and run it again.

这篇关于将SQL粘贴到MySQL命令行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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