Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    Singapore
    Posts
    200

    Unanswered: run a query in batch file

    Hi,

    I want to run a batch file that executes a command in SQL as select Count(*) from sometable;

    when I edit the bat files as such it goes till the command prompt,but home to make the rest execute:

    contents for BAT file:

    mysql test;

    select COunt(*) from a;

    ##############

    It stops at the mysql > prompt.

    Please help me to run the batch file.

    Thanks

    micky

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    What you say seems normal to me : you execute "mysql test" on the OS prompt, which launches mysql, but from now on, you will not execute the rest of your batch until you get out of mysql. What you should do is, as said in the mysql manual, launching mysql with a sql script by doing so :

    mysql db_name < script.sql > output.tab

    or telling mysql to execute a statement, with something like this :

    mysql --execute statement db_name

    which in your case would be (not sure about the quotes) :

    mysql --execute 'select Count(*) from a;' test

    Regards,

    RBARAER

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •