Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Location
    india- new delhi
    Posts
    31

    Unanswered: mysql script file (.sql) running problem

    My system requirement is to execute sequence of mysql commands from ubuntu terminal,
    For testing i create a file query.sql on the desktop that have a content like:-
    create table aa (id int);
    create tab bb (id int);
    create table cc (id int);
    i execute this with command like:-

    zero@zero-desktop:~/Desktop$ mysql --user=root --password=admin --database=zero <query.sql

    my problem is if any query fail, script stop executing,
    Can anybody tell me how i prevent it[ here only second have wrong syntax, first and third should be run] i want to execute whole script, if any fail avoid it and start again from next query and generate a file where it shows error list........
    Amit Pathak
    S/w Developer
    Zero Systems Pvt Ltd..

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Try using the --force parameter when running mysql command line utility. This continues executing regardless of the errors encountered. If you type in mysql --help there are lots of parameters which might be useful to you.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Feb 2011
    Location
    india- new delhi
    Posts
    31
    Quote Originally Posted by it-iss.com View Post
    Try using the --force parameter when running mysql command line utility. This continues executing regardless of the errors encountered. If you type in mysql --help there are lots of parameters which might be useful to you.
    yes sir it works- i used query like
    zero@zero-desktop:~/Desktop$ mysql --force --user=root --password=admin --database=zero <query.sql
    it execute whole script, is there any command , with the help of that we can create a file where all error ( if exist in script file) placed when script finished..
    here it shows 2 genuine error, i want to display this on file??????????/ [because it can use as long it exist]

    ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tab bb (id int)' at line 1
    ERROR 1050 (42S01) at line 3: Table 'cc' already exists
    Amit Pathak
    S/w Developer
    Zero Systems Pvt Ltd..

  4. #4
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Have you considered outputing all the contents to a file and then filtering the file on a keyword. This might be easier than splitting the errors out into one file and the log into another.

    In Linux/UNIX/Mac OS X there is a very useful tool for this called "grep". If you issue the following command:

    Code:
    shell> grep ^ERROR logfile
    This will return all lines whose first word is ERROR
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  5. #5
    Join Date
    Feb 2011
    Location
    india- new delhi
    Posts
    31
    what about this-
    i solved this problem by following command:-
    zero@zero-desktop:~$ mysql --force --user=root --password=admin --database=zero <query.sql 2>error.log
    after running this it creating a file in desktop with error.log it have all error............
    Amit Pathak
    S/w Developer
    Zero Systems Pvt Ltd..

Tags for this Thread

Posting Permissions

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