MySQL::Dump::Parser::XS - mysqldump SQL parser
use MySQL::Dump::Parser::XS; open my $fh, '<:encoding(utf-8)', 'backup.sql' or die $!; my %rows; my $parser = MySQL::Dump::Parser::XS->new; while (my $line = <$fh>) { my @rows = $parser->parse($line); my $table = $parser->current_target_table(); push @{ $rows{$table} } => @rows if $table; } for my $table ($parser->tables()) { my @columns = $parser->columns($table); my $row = $rows{$table}; print "[$table] id:$row->{id}\n"; }
MySQL::Dump::Parser::XS is mysqldump parser written in C/XS. This module provides schema/data loader from mysqldump output SQL directly. No need mysqld.
mysqldump
mysqld
new()
Creates a new parser instance. This manages parsing states and table's meta information in the parsing context.
reset()
Re-initialize parsing context.
parse($line)
Parse a line of mysqldump output.
current_target_table()
Get current target table name in the parsing context.
columns($table_name)
Get column names as LIST for the table of $table_name. This method can get columns from already parsed tables only.
$table_name
tables()
Get table names as LIST. This method can get tables from already parsed tables only.
Some mysqldump output include poor table schema information only. So if you just need rich table schema information, I suggest using DBIx::Inspector to solve the problem.
Copyright (C) karupanerura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
karupanerura <karupa@cpan.org>
To install MySQL::Dump::Parser::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::Dump::Parser::XS
CPAN shell
perl -MCPAN -e shell install MySQL::Dump::Parser::XS
For more information on module installation, please visit the detailed CPAN module installation guide.