If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > mysql script file (.sql) running problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-11, 03:35
rohitamitpathak rohitamitpathak is offline
Registered User
 
Join Date: Feb 2011
Location: india- new delhi
Posts: 31
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..
Reply With Quote
  #2 (permalink)  
Old 03-29-11, 05:08
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 03-29-11, 07:19
rohitamitpathak rohitamitpathak is offline
Registered User
 
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..
Reply With Quote
  #4 (permalink)  
Old 03-29-11, 08:30
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
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
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #5 (permalink)  
Old 03-31-11, 04:00
rohitamitpathak rohitamitpathak is offline
Registered User
 
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..
Reply With Quote
Reply

Tags
mysql, mysql script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On