0

The following batch script produces the error shown below.

@echo off
set MUSER=root
set MPASS=admin
set MHOST=localhost
set DB=test_officebox_admin
set MBIN="C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin"
set scriptpath="C:\Users\unmesh.ghatbandhe\Desktop\testdatasql"
set scriptfile=%scriptpath%\test.sql
cd \
cd %MBIN%
PAUSE
call mysql -u%MUSER% -p%MPASS% -h%MHOST% -D%DB% < %scriptfile%

executed batch script leads to error

I do have many scripts in Sql files when I run it manually it executes all scripts after error it executes another script mysql> Source filename.sql but is not working for batch file. Can you help me to make it executable?

Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Well, it tells you that you are trying to insert a row with an id that is already in your table. We have no clue what your script is supposed to to. If it is fine that the row already exists, and you simply want to ignore it, you can use a method from [this question](https://stackoverflow.com/q/29545733/6248528), otherwise you will have to find out what you want to do with this row (e.g. is the table supposed to be empty, do you want to use an autoincrement instead of a fixed id, ...) – Solarflare Aug 31 '17 at 10:58
  • @Solarflare Yes I wanted to Ignore the script if it is already inserted and then it should take another script for execution from the same file as my file contains `1000s` of scripts.and I am doing it from batch file and every time my scripts will change So I just wanted to Ignore the results whatever it is. – Unmesh Ghatbandhe Aug 31 '17 at 11:11
  • "I want to take another script from the same file" makes no sense, the file *IS* the script (if we are talking about the .sql-file as "the file"). Also, as I said, without seeing the script, we cannot tell you what you have to change in there (or in the logic of your batch). If you just want to ignore the already existing rows, replace the inserts in your sql-script according to the link in my first comment (e.g. add "ignore" to every insert-statement). Or are you looking to continue the script on error, then see e.g. [here](https://stackoverflow.com/q/11263018/6248528) – Solarflare Aug 31 '17 at 11:30
  • well, there are various ways, but you can either do `INSERT IGNORE` or do write an "UPSERT" query in other words Insert if not exist, or update when does. it is pretty straight forward. I could post these options as an answer, but will probably just get voted down. – Gerhard Aug 31 '17 at 11:35
  • **INSERT INTO `tbmreportfieldcnfgrtndtl` (`CnfgrtnDtlId`, `CnfgrtnId`) VALUES('28586','317'); INSERT INTO `tbmreportfieldcnfgrtndtl` (`CnfgrtnDtlId`, `CnfgrtnId`) VALUES('28587','318'); INSERT INTO `tbmreportfieldcnfgrtndtl` (`CnfgrtnDtlId`, `CnfgrtnId`) VALUES('28588','319'); INSERT INTO `tbmreportfieldcnfgrtndtl` (`CnfgrtnDtlId`, `CnfgrtnId`) VALUES('28589,'320');** These are the queries in one file there are many queries I dont want to change anything in the Qury wanted to execute only – Unmesh Ghatbandhe Aug 31 '17 at 11:55

0 Answers0