Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Dump

Status
Not open for further replies.

wapboy

Technical User
Oct 26, 2002
13
0
0
GB
How do I do a dump of a MySQL table from a PERL script?

Thanks
Paul
 
How do you normally do it?

--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
I normally use phpMyAdmin, but the table is too large and this times out - so maybe doing it thru a Perl script might work
 
You could also use Net::MySQL and drop the returned data from MySQL into and array or hash...comme ca:
Code:
use Net::MySQL;
  
  my $mysql = Net::MySQL->new(
      # hostname => 'mysql.example.jp',   # Default use UNIX socket
      database => 'your_database_name',
      user     => 'user',
      password => 'password'
  );

  # INSERT example
  $mysql->query(q{
      INSERT INTO tablename (first, next) VALUES ('Hello', 'World')
  });
  printf "Affected row: %d\n", $mysql->get_affected_rows_length;

  # SLECT example
  $mysql->query(q{SELECT * FROM tablename});
  my $record_set = $mysql->create_record_iterator;
  while (my $record = $record_set->each) {
      printf "First column: %s Next column: %s\n",
          $record->[0], $record->[1];
  }
  $mysql->close;
as demonstrated in the CPAN notation:

I personally have never had any need to link perl up to MySQL as yet but if I did then this would be my most likely plan of attack!

Rob Waite
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top