POE::Component::Proxy::MySQL - A MySQL POE Proxy
This modules helps building a MySQL proxy in which you can write handler to deal with specific queries.
You can modifiy the query, write a specific response, relay a query or do wahtever you want within each handler.
This is the evolution of POE::Component::DBIx::MyServer, it uses Moose and POE.
First you create a server class that extends POE::Component::Server::MySQL.
package MyMySQL; use Moose; extends 'POE::Component::Server::MySQL'; with 'MooseX::Getopt';
Then in a perl script you can instantiate your new server
use MyMySQL; my $server = MyMySQL->new_with_options(); $server->run;
In the MyMySQL namespace you can add roles which will act as handlers for your trapped queries:
package MyMySQL::Hello; use POE; use MooseX::MethodAttributes::Role; sub fortune : Regexp('qr{fortune}io') { my ($self) = $_[OBJECT]; my $fortune = `fortune`; chomp($fortune); $self->client_send_results( ['fortune'], [[$fortune]] ); }
Then run your proxy
perl mymysql.pl --src_address localhost --src_port 23306 --dst_address localhost --dst_port 3306
and finally
[eriam@fbsd ~]# mysql -u root -pxxx --host localhost --port 23306 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.40 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> fortune(); +---------------------------------------------------------------------+ | fortune | +---------------------------------------------------------------------+ | How sharper than a hound's tooth it is to have a thankless serpent. | +---------------------------------------------------------------------+ 1 row in set (0,10 sec)
Eriam Schaffter, eriam@cpan.org with original work done by Philip Stoev in the DBIx::MyServer module.
eriam@cpan.org
None that I know.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
To install POE::Component::Proxy::MySQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::Proxy::MySQL
CPAN shell
perl -MCPAN -e shell install POE::Component::Proxy::MySQL
For more information on module installation, please visit the detailed CPAN module installation guide.