View Single Post
Old 06-30-2006, 10:01 PM   #11 (permalink)
fantom1979
Hall Of Famer
 
fantom1979's Avatar
 
Join Date: Jul 2002
Location: Detroit, MI
Posts: 3,496
Thanks: 42
Thanked 48x in 25 posts
Quote:
Originally Posted by Andreas Raht
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 -pp***word -t database_name < ".$path.$name);
  
 }
 
}
closedir(DIRHANDLE);
Thank you
fantom1979 is offline   Reply With Quote