将参数从批处理文件传递到MYSQL脚本 [英] Pass parameter from Batch file to MYSQL script
问题描述
我很难相信这个问题以前从未问过,它一定是!我正在处理需要运行一些sql命令的批处理文件.所有解释此问题的教程均不起作用(请参考此链接:将参数传递给sql脚本无疑有人会提到)!我已经尝试了该网站上的其他帖子,但仍然没有任何效果.
I'm having a really hard time believing this question has never been asked before, it MUST be! I'm working on a batch file that needs to run some sql commands. All tutorials explaining this DO NOT WORK (referring to this link:Pass parameters to sql script that someone will undoubtedly mention)! I've tried other posts on this site verbatim and still nothing is working.
我的观察方式有两种: 1.弄清楚如何调用我的基本MYSQL脚本并指定参数或. 2.找到一个等效的"USE;"批量运行的命令
The way I see it, there are two ways I can approach this: 1. Either figure out how to call my basic MYSQL script and specify a parameter or.. 2. Find an equivalent "USE ;" command that works in batch
到目前为止我的批处理文件:
My Batch file so far:
:START
@ECHO off
:Set_User
set usrCode = 0
mysql -u root SET @usrCode = '0'; \. caller.sql
简单地说,我想将'usrCode'传递给我的MYSQL脚本'caller.sql',如下所示:
Simply put, I want to pass 'usrCode' to my MYSQL script 'caller.sql' which looks like this:
USE `my_db`;
CALL collect_mismatch(@usrCode);
我知道过程是另一个完整的话题,但是假设该过程运行良好.我只是无法将我的参数从Batch转到MYSQL.
I know that procedures are a whole other topic to get into, but assume that the procedure is working just fine. I just can't get my parameter from Batch to MYSQL.
理想情况下,我希望拥有'USE'&我的批处理文件中有调用"命令,但是在调用过程之前,找不到能使我在批处理中选择数据库的任何内容.那时我尝试了上面的链接,该链接具有简单的命令行输入,您可以参加比赛了,但事实并非如此.
Ideally I would like to have the 'USE' & 'CALL' commands in my Batch file, but I can't find anything that let's me select a database in Batch before CALLing my procedure. That's when I tried the above link which boasts a simple command line entry and you're off to the races, but it isn't the case.
任何帮助将不胜感激.
推荐答案
这将起作用;
echo SET @usrCode = '0'; > params.sql
type params.sql caller.sql | mysql -u root dbname
这篇关于将参数从批处理文件传递到MYSQL脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!