0

I am going to write a .bat file to realize this function: to detect whether the database and the table existed,if not exist,create them. I tried to write the bat file like this:

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -h localhost -u root --password= 
select * from martin.aaaperson

Then in cmd when I execute this, the bat file will not run the query until after I exit from mysql.

C:\000test>"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -h localhost
-u root --password=
(information of mysql)
mysql> exit
Bye
C:\000test>select * from martin.aaaperson
"select" is not knowby cmd
1
  • it seems the first problem i've solved like this:"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -h P30LSimul -u root --password= <ccc.sql but it seems i should have also a sql file Commented Aug 8, 2014 at 14:32

1 Answer 1

1

you need to do something like

mysql.exe -u root -p  < your_sql_commands_in_this_file.sql

Put your sql into a file, and then redirect that file into mysql, so it's used as actual commands.

Batch files can only work at the command line. Once you run mysql.exe the .bat file is suspended until mysql exits, and then the batch resumes. That means by the time the batch fires back up again, you've exited mysql and are no longer doing sql operations - you're just back at a command prompt.

Sign up to request clarification or add additional context in comments.

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.