read mySQL dump file back into empty database
Posted on 2007-11-15
Hi, I'm having a heck of a time importing a mysqldump file back into my database using Perl.
documentation and Google searches suggest this:
system "mysql -uUSER -pPASS DBNAME < source $prodFilename";
but this doesn't work. I have had problems with system() before, and have resolved it by separating all parameters using commas, like this:
system("mysql", "-uUSER", "-pPASS", etc....);
however, the in-file operator "<" doesn't appear to work in this context
from the command line, I'm able to use the following command:
$ mysql -uUSER -pPASS -e "source 07-11-15_TEST.sql" DBNAME
and it does what I want
But when I translate this into a system() call:
system("mysql", "-uUSER", "-pPASS", "-e \"source $prodFilename\"", "DBNAME");
I get an SQL error - it doesn't like the "source" command for some reason
I've tried going another route, using DBI:
$sth = $dbh->do("LOAD DATA INFILE '$prodFilename'");
but I get a mysql error on the file name.
Any help would be appreciated!