批处理脚本向MySQL数据库发出命令? [英] Batch script to issue commands to mySQL db?

查看:96
本文介绍了批处理脚本向MySQL数据库发出命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理脚本,该脚本将连接到mySQL数据库并发出删除命令:

I am trying to create a batch script that would connect to a mySQL database and issue a delete command:

@echo off
echo Resetting all assessments...
mysql -hlocalhost -urdfdev -p%1 rdf_feedback
delete from competency_question_answer;

我将运行此脚本,并提供密码作为命令行参数,但此脚本所做的只是将其连接到数据库,并显示mysql>提示符.从mysql退出后,其余的批处理命令将开始执行(并且失败,不足为奇).

I will run this script providing the password as a command-line argument, but all this script does is, connects to the database, and the mysql> prompt will be shown. After I exit from mysql, the rest of the batch commands get to execute (and fail, no surprise).

如何将SQL命令从批处理脚本传递到mysql控制台?这有可能吗?

How can I pass the SQL commands from the batch script to the mysql console? Is this even possible?

推荐答案

您需要使用命令行工具.我不知道MySQL是否存在,但对于SQL,则存在SQLCMD,对于Oracle,则存在OSQL.

You need to use command line tools. I don't know if there exists any for MySQL but for SQL there is SQLCMD and for Oracle there is OSQL.

您还可以做类似这样的事情.

What you can also do is something like this.

mysql -uuser -ppass < foo.sql

其中foo.sql是要执行的命令.

Where foo.sql is the commands you want to execute.

这篇关于批处理脚本向MySQL数据库发出命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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