I have a file with several sql language insert statements. I want perl to use the import file feature built into mysql. Problem is i don't see the nice error statement i get when i run the command from a shell. When i run this command on my linux server it tells me i have an sql syntax error and what line it is on.
mysql -u USERNAME -pPASSWORD MYDATABASE < /home/www/commands.sql
I am trying to have perl do the same thing, and print the error message out to me. But no error output. I've tried this a couple of ways to no avail, the code below does not return the error message i need.
use strict;
my $usr = "USERNAME";
my $pass = "PASSWORD";
my $db = "MYDATABASE";
my $file = "/var/www/commands.sql";
open(HAND,"mysql -u $user -p$pass $db < $file |") or return "fail";
while (<HAND>){
print $_;
}close HAND;
exit;
Note, if there are no sql errors in my file, mysql will carry out my sql commands and insert the rows as expected.
thanks for reading,
jtrue
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.