View Single Post
Old 06-30-2006, 04:57 AM   #10 (permalink)
Andreas Raht
Administrator
 
Andreas Raht's Avatar
 
Join Date: Jun 2002
Location: Hollern/Stade/Germany
Posts: 6,720
Thanks: 200
Thanked 1,393x in 513 posts
Here is the promised Perl code to import the sql files on a server with Perl and MySQL available.
This code has not been tested and we do not offer any support for it. Use it at your own risk!

It just reads a directory into a list, then skips to the list, looking for files with the wanted file name extension, then calls mysql for each file which it finds. BTW you could also add another line to unlink (delete) the file after importing it, then add the script to your crontab to be executed every 30 minutes, which will automate the process a little bit. Just an idea.

Code:
#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);

my $path="/usr/local/data/whatever/";
opendir(DIRHANDLE, $path) || die "Cannot opendir /some/path: $path!";
my @dirlist=readdir(DIRHANDLE);
my $name;
foreach $name(@dirlist) 
{
 if (index($name,".mysql.sql") > 0)
 {
  print "Importing ".$path.$name."...\n";
  system("mysql -uusername -ppassword -t database_name < ".$path.$name);
  
 }
 
}
closedir(DIRHANDLE);
Andreas Raht is offline   Reply With Quote