MySQL

Select random rows from a table in MySQL

2010
12
May

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.



Resolve Net::MySQL Hang problem if the database result has only 1 row or is empty

2010
26
Mar

Net::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.

Sample Net::MySQL code

#!/usr/bin/perl
 
use Net::MySQL;
 
$mysql = Net::MySQL->new(
	hostname => 'localhost',
	database => 'db',
	user     => 'user',
	password => 'password',
);
 
$gid = 1;
 
$mysql->query('SELECT * FROM table WHERE id = 1');
 
if ($mysql->has_selected_record) {
	my $record_set = $mysql->create_record_iterator;
	while(my $record = $record_set->each) {

Read More

Apache Solr MySQL Sample Data Config

2010
22
Feb
2

ApacheSolr is an indexing server from apache. It is written in Java and can be used to make search pages on your website. Most Websites use a MySQL database to store its data and standard MySQL search using SQL or FULLTEXT Searching by MySQL. But with ApacheSolr we can not only search but also improve the search results. Solr recognizes plurals and similar words like read, reading or A-DATA, adata etc. Therefore Solr returns more efficient search results.

Read More

Syndicate content