Installing MySql Handlersocket in Ubuntu Natty for Ruby

Install

sudo apt-get install mysql-server -y;
sudo apt-get install handlersocket-doc -y;
sudo apt-get install handlersocket-mysql-5.1 -y;
sudo apt-get install libhsclient-dev -y;

Configure

#/etc/mysql/my.cnf -- under mysqld section
loose_handlersocket_port = 9998
loose_handlersocket_port_wr = 9999
loose_handlersocket_threads = 16
loose_handlersocket_threads_wr = 1
open_files_limit = 65535 

Start

mysql -e "install plugin handlersocket soname 'handlersocket.so';"
sudo /etc/init.d/mysql restart

# should show lots of handlersocket processes
mysql -e "show processlist;"

Use

gem install handlersocket

require 'handlersocket'
h = HandlerSocket.new(:host => '127.0.0.1', :port => '9998')

# open PRIMARY index on widgets.user table, assign it ID #1
h.open_index(1, 'widgets', 'user', 'PRIMARY', 'user_name,user_email,created')
...

more of this can be found at ruby handlersocket introduction and ActiveRecord Handlersocket gem

Leave a comment