I. Installation
1. Download The mysql-5.1.54.tar.gz and unzip it to/root/mysql/mysql-5.1.54 directory
2. Download The ahiguti-HandlerSocket-Plugin-for-MySQL-1.0.6-94-g98b14c3.tar.gz and unzip it to the/root/mysql/ahiguti-HandlerSocket-Plugin-for-MySQL-98b14c3 directory
3. Compile and install mysql to/usr/local/mysql5.1 in the form of dynamic compilation
4. Compile the HandlerSocket plug-in the/root/mysql/ahiguti-HandlerSocket-Plugin-for-MySQL-98b14c3 directory.
#./Autogen. sh
#. /Configure -- with-mysql-source =/root/mysql/mysql-5.1.54 -- with-mysql-bindir =/usr/local/mysql5.1/bin -- with-mysql-plugindir =/usr/ local/mysql5.1/lib/mysql/plugin
With-mysql-source indicates the MySQL source code directory, with-mysql-bindir indicates the MySQL binary executable file directory (that is, the directory where mysql_config is located), and with-mysql-plugindir indicates the MySQL plug-in Directory
If you do not know where the directory is, you can query it as follows:
Mysql> show variables like 'in in % ';
+ --------------- + ----------------------- +
| Variable_name | Value |
+ --------------- + ----------------------- +
| Plugin_dir |/usr/lib/mysql/plugin |
+ --------------- + ----------------------- +
Compile and install
# Make & make install
Ii. Configure MySQL
# Vi/etc/my. cnf
[Mysqld]
Loose_handlersocket_port = 9998
# The port number to bind to (for read requests)
Loose_handlersocket_port_wr = 9999
# The port number to bind to (for write requests)
Loose_handlersocket_threads = 16
# The number of worker threads (for read requests)
Loose_handlersocket_threads_wr = 1
# The number of worker threads (for write requests)
Open_files_limit = 65535
# To allow handlersocket accept implements concurren connections, make open_files_limit as large as possible.
Activate the HandlerSocket plug-in and execute commands on the client.
Mysql> install plugin handlersocket soname 'handlersocket. so ';
View handlersocket Process
Mysql> show processlist
+ ---- + ------------- + ----------------- + --------------- + --------- + ------ + ----------------------------------------- + ------------------ +
| Id | User | Host | db | Command | Time | State | Info |
+ ---- + ------------- + ----------------- + --------------- + --------- + ------ + ----------------------------------------- + ------------------ +
| 1 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 2 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 3 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 4 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 5 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 6 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 7 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 8 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 9 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 10 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 11 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 12 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 13 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 14 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 15 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 16 | system user | connecting host | NULL | Connect | NULL | handlersocket: mode = rd, 0 conns, 0 active | NULL |
| 17 | system user | connecting host | handlersocket | Connect | NULL | handlersocket: mode = wr, 0 conns, 0 active | NULL |
View the port occupied by the system process
# Lsof-I: 9998
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Mysqld 2731 mysql 11u IPv4 571386 TCP *: 9998 (LISTEN)
# Lsof-I: 9999
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Mysqld 2731 mysql 29u IPv4 571403 TCP *: 9999 (LISTEN)
Iii. Test and use
Create a test table in database test
Create table 'user '(
'User _ id' INT (10) unsigned not null,
'User _ name' VARCHAR (50) default null,
'User _ email 'VARCHAR (255) default null,
'Created 'datetime default null,
Primary key ('user _ id '),
KEY 'index _ 01' ('user _ name ')
) ENGINE = INNODB
Insert Test Data
Insert into user values (1, "John", "john@test.com", CURRENT_TIMESTAMP );
Insert into user values (2, "Kevin", "Kevin@test.com", CURRENT_TIMESTAMP );
Insert into user values (3, "Dino", "Dino@test.com", CURRENT_TIMESTAMP );
Compile the Perl client and execute it in the/root/mysql/ahiguti-HandlerSocket-Plugin-for-MySQL-98b14c3 directory
#./Autogen. sh
#./Configure -- disable-handlersocket-server
# Make & make install
# Cd perl-Net-HandlerSocket
# Perl Makefile. PL
# Make & make install
Perl program file:
Php code
#! /Usr/bin/perl
Use strict;
Use warnings;
Use Net: HandlerSocket;
#1. establishing a connection
My $ args = {host => 'localhost', port => 9998 };
My $ hs = new Net: HandlerSocket ($ args );
#2. initializing an index so that we can use in main logics.
# MySQL tables will be opened here (if not opened)
My $ res = $ hs-> open_index (0, 'test', 'user', 'index _ 0', 'user _ name, user_email, created ');
Die $ hs-> get_error () if $ res! = 0;
#3. main logic
# Fetching rows by id
# Execute_single (index id, cond, cond value, max rows, offset)
$ Res = $ hs-> execute_single (0, '=', ['kevin '], 1, 0 );
Die $ hs-> get_error () if $ res-> [0]! = 0;
Shift (@ $ res );
For (my $ row = 0; $ row <1; ++ $ row ){
My $ user_name = $ res-> [$ row + 0];
My $ user_email = $ res-> [$ row + 1];
My $ created = $ res-> [$ row + 2];
Print "$ user_name \ t $ user_email \ t $ created \ n ";
}
#4. closing the connection
$ Hs-> close ();
#! /Usr/bin/perl
Use strict;
Use warnings;
Use Net: HandlerSocket;
#1. establishing a connection
My $ args = {host => 'localhost', port => 9998 };
My $ hs = new Net: HandlerSocket ($ args );
#2. initializing an index so that we can use in main logics.
# MySQL tables will be opened here (if not opened)
My $ res = $ hs-> open_index (0, 'test', 'user', 'index _ 0', 'user _ name, user_email, created ');
Die $ hs-> get_error () if $ res! = 0;
#3. main logic
# Fetching rows by id
# Execute_single (index id, cond, cond value, max rows, offset)
$ Res = $ hs-> execute_single (0, '=', ['kevin '], 1, 0 );
Die $ hs-> get_error () if $ res-> [0]! = 0;
Shift (@ $ res );
For (my $ row = 0; $ row <1; ++ $ row ){
My $ user_name = $ res-> [$ row + 0];
My $ user_email = $ res-> [$ row + 1];
My $ created = $ res-> [$ row + 2];
Print "$ user_name \ t $ user_email \ t $ created \ n ";
}
#4. closing the connection
$ Hs-> close ();
Download the hs4j-0.1 package.
Java program file:
Java code
Import java. SQL. ResultSet;
Import com. google. code. hs4j. HSClient;
Import com. google. code. hs4j. HSClientBuilder;
Import com. google. code. hs4j. IndexSession;
Import com. google. code. hs4j. impl. HSClientBuilderImpl;
Public class TestNoSQL {
Public static void main (String [] args) throws Exception {
HSClientBuilder hscb = new HSClientBuilderImpl ();
Hscb. setServerAddress ("10.10.10.2", 9999 );
HSClient SCS = hscb. build ();
IndexSession is = SCS. openIndexSession (1, "test", "user", "INDEX_01", new String [] {"user_name", "user_email", "created "});
// Insert
Is. insert (new String [] {"ezerg", "ezerg@126.com", "13:04:33 "});
Final String [] keys = {"ezerg "};
// Query
ResultSet rs = is. find (keys );
While (rs. next ()){
System. out. println ("name =" + rs. getString (1 ));
System. out. println ("email =" + rs. getString (2 ));
}
// Delete
// Is. delete (keys );
// Update
// Is. update (keys, new String [] {"ezerg", "ezerg@163.com", "13:04:33"}, FindOperator. EQ );
// Close the connection
HSF. shutdown ();
}
}