2

Basically my batch file contains:

mysql -u root -pMypassword use myTableDB update myTable set extracted='Y'

but for some syntax error it doesn't update the table. However, when i run through command line:

mysql -u root -pMypassword use myTableDB
mysql update myTable set extracted='Y'

through command line it works. Anyone can point me what syntax error i have on the batch file.

4
  • Would that first command work if you typed it into the command line? Commented Apr 18, 2015 at 0:28
  • @SomethingDark, it doesn't work and it does not throw any error besides Usage: mysql [OPTIONS] [database] Commented Apr 18, 2015 at 0:32
  • Do the two separate commands work when you put them in the batch file? Commented Apr 18, 2015 at 0:33
  • @SomethingDark, it doesn't either Commented Apr 18, 2015 at 0:34

2 Answers 2

3

The cleanest way would be the following:

mysql -u root -pMypassword -DmyTableDB -ANe"update myTable set extracted='Y'"

or if you want the SQL command placed in a variable, you could do this

set sqlstmt=update myTable set extracted='Y'
mysql -u root -pMypassword -DmyTableDB -ANe"%sqlstmt%"

Here is an example i just ran

set sqlstmt=show databases
mysql -u root -pMypassword -DmyTableDB -ANe"%sql%"

and I got this

C:\WINDOWS\system32> set sqlstmt=show databases
C:\WINDOWS\system32> mysql ... -ANe"%sql%"
+--------------------+
| information_schema |
|              mysql |
| performance_schema |
|               test |
+--------------------+

C:\WINDOWS\system32>
Sign up to request clarification or add additional context in comments.

Comments

1

mysql client reads SQL commands from STDIN. To do what you want, you would have to do something like the following in your batch file:

echo "update myTable set extracted='Y'" | mysql -u root -pMypassword myTableDB

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.