这是我的第一个批处理文件,我一直无法找到答案(或者我可以破译的线索)。编程新手,并尝试在单个批处理文件中运行多个.sql语句。我能这样做。问题是,flie只处理一个库存@,而底部的2个COUNTS文件重复 - 所以我需要在用户更改第一个.sql文件中的库存符号后运行它们并让它们循环运行直到输入最后一个库存 - 然后在最后运行COUNTS文件。
@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\load_csv_data_MySQL.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DEFAULT_updates.sql"
:this is where I need to have the file either loop back through the above scripts with
:a different stock (with files above updated by the batch user who has access to the .sql files) or when
:all stocks have been entered, to continue to the 2 .sql scripts below
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit
非常感谢任何帮助(请记住我完全缺乏批处理文件的经验)!附:这是个人作业,不适用于任何类型的学校,我是自己 现在仅使用网络进行教学(以及Murach的MySQL书籍)......
谢谢!
答案 0 :(得分:0)
如果mysql
命令不会改变,这将正常工作:
@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
:start
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\load_csv_data_MySQL.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DEFAULT_updates.sql"
choice /m "Restart Operation ?"
if %errorlevel% equ 1 goto :start
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit
如果没有,我无法帮助,因为我自己并不熟悉
希望这会有所帮助。
答案 1 :(得分:0)
@echo off
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
:again
set "stock="
set /p stock="enter stock symbol "
if not defined stock goto final
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\load_csv_data_MySQL.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_DAILY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment 1\good scripts\derived_MONTHLY.sql"
mysql -h -u -p -Dstock_market < "C:\mysql assignment\1\good scripts\derived_DEFAULT_updates.sql"
goto again
:final
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_daily.sql"
mysql -h -uroot -p -Dstock_market < "C:\mysql assignment 1\good scripts\INSERT_INTO_COUNTS_monthly.sql"
exit
这应该让你开始 - 将接受股票代码;按 Enter 应运行最后两个并退出。
但是我收集输入的股票必须用于修改循环中的4个脚本。这是一个完全不同的任务。并非不可能,但确实增加了复杂性。您应该能够让.sql
脚本接受一个参数(我不是.sql
脚本的专家,因此我不知道具体如何)或者只是从一个重建.sql
模板,替换键字符串......