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 ();
}
}