简体   繁体   English

将参数从批处理文件传递到MYSQL脚本

[英]Pass parameter from Batch file to MYSQL script

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. 我正在处理需要运行一些sql命令的批处理文件。 All tutorials explaining this DO NOT WORK (referring to this link: Pass parameters to sql script that someone will undoubtedly mention)! 解释这个的所有教程都不起作用(参考这个链接:将参数传递给sql脚本 ,有人无疑会提到)! I've tried other posts on this site verbatim and still nothing is working. 我已经在这个网站上逐字尝试了其他帖子,但仍然没有任何工作。

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 ;" 我看到它的方式,有两种方法可以解决这个问题:1。要么弄清楚如何调用我的基本MYSQL脚本并指定参数或.. 2.找到一个等效的“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

Simply put, I want to pass 'usrCode' to my MYSQL script 'caller.sql' which looks like this: 简单地说,我想将'usrCode'传递给我的MYSQL脚本'caller.sql',如下所示:

USE `my_db`;
CALL collect_mismatch(@usrCode);

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. 我只是无法从Batch到MYSQL获取参数。

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. 理想情况下,我想在我的批处理文件中使用'USE'和'CALL'命令,但是在找到我的程序之前,我找不到让我在批处理中选择数据库的任何内容。 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. 那时候我尝试了上面的链接,它拥有一个简单的命令行输入,而你正在参加比赛,但事实并非如此。

Any help would be greatly appreciated. 任何帮助将不胜感激。

This will work; 这将有效;

echo SET @usrCode = '0'; > params.sql
type params.sql caller.sql | mysql -u root dbname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM