一开始觉得 安装 Handlet Socket Plugin 是非常容易的。结果还是绕了大半圈。 我以常规方式编译mysql mysql lib 静态编译 gcc O3 优化,结果 Handler Socket Plugin 死活载入不了。 后来发现 Handler Socket Plugin 是 .so的也就是动态编联的。所以按我常规的编译方式死活不行。

 ./configure CC=gcc CFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -O3" CXX=g++ CXXFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -felide-constructors -fno-rtti -O3" \
--prefix=/opt/mysql5/ \
--enable-largefile \
--with-charset=utf8 \
--with-pthread \
--with-unix-socket-path=/tmp/mysql.sock \
--enable-assembler \
--enable-thread-safe-client \
--without-debug \
--with-atomic-ops=smp  \
--with-client-ldflags=-all-static \
--with-big-tables \
--without-ndb-debug \
--with-embedded-server \
--without-docs \
--without-man \
--with-plugins=all

下载Handler Socket Plugin

git clone https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git

编译Handler Socket Plugin:

./autogen.sh
/configure --with-mysql-source=/tmp/mysql-5.1.50 --with-mysql-bindir=/opt/mysql5/bin
make && make install

配置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 many concurrent
    # connections, make open_files_limit as large as
    # possible.

加载Handler Socket Plugin 模块:

mysql> install plugin handlersocket soname 'handlersocket.so';

查看运行状况:

mysql> show processlist;
+----+-------------+-----------------+---------------+---------+------+-------------------------------------------+------------------+
| Id | User        | Host            | db            | Command | Time | State                                     | Info             |
+----+-------------+-----------------+---------------+---------+------+-------------------------------------------+------------------+
|  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 | handlersocket | Connect | NULL | handlersocket: mode=wr, 0 conns, 0 active | NULL             |
|  8 | root        | localhost       | NULL          | Query   |    0 | NULL                                      | show processlist |
+----+-------------+-----------------+---------------+---------+------+-------------------------------------------+------------------+
6 rows in set (0.00 sec)