In order to select a random row from MySQL, we can order the rows by a random number and then pick the first row.
SELECT * FROM node ORDER BY rand() limit 1;
The above query randomly selects a row from the table node.
read onNet::MySQL is a simple MySQL perl Client to connect to MySQL servers. But Net::MySQL hangs if your result set is having just one row.
#!/usr/bin/perl
use Net::MySQL;
$mysql = Net::MySQL->new(
hostname => 'localhost',
database => 'db',
user => 'user',
password = …
read on