Search

centos5.4 MySQL 5.6 を導入して HandlerSocket を導入する

2015年10月19日

いかからmysql-5.6.13.tar.gzをダウンロードし、/usr/local/srcに保管
http://www.mysql.com/downloads/mysql/

groupadd mysql
useradd -g mysql mysql

CMakeインストール

yum install cmake

# cd /usr/local/src
# tar zxvf mysql-5.6.13.tar.gz

mysql5.6のインストール

cd mysql-5.6.13
cmake . -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install

handlersocketをソースからインストール

モジュール取得

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

このモジュールだとmakeで以下エラーが発生する。

・
・
・
database.cpp:819: error: within this context
database.cpp: In member function ‘virtual void dena::dbcontext::cmd_open(dena::dbcallback_i&, const dena::cmd_open_args&)’:
database.cpp:1018: error: cannot convert ‘MEM_ROOT*’ to ‘Open_table_context*’ for argument ‘3’ to ‘bool open_table(THD*, TABLE_LIST*, Open_table_context*)’
make[2]: *** [handlersocket_la-database.lo] Error 1
make[2]: Leaving directory/root/HandlerSocket-Plugin-for-MySQL-master/handlersocket'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/HandlerSocket-Plugin-for-MySQL-master'
make: *** [all] Error 2

ということで、以下から取得

# git clone git://github.com/DeNA/HandlerSocket-Plugin-for-MySQL.git
# ./autogen.sh
# ./configure --with-mysql-source=/usr/local/src/mysql-5.6.13 --with-mysql-bindir=/usr/local/mysql/bin --with-mysql-plugindir=/usr/local/mysql/lib/plugin
# make
# make install

アップグレード

# mysql_upgrade -p root

handlersocket.soをインストール

>install plugin handlersocket soname 'handlersocket.so';
Query OK, 0 rows affected (0.23 sec)

インストールされたプラグインを確認

>show plugin;
+----------------------------+----------+--------------------+------------------+---------+
| Name                       | Status   | Type               | Library          | License |
+----------------------------+----------+--------------------+------------------+---------+
| binlog                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| mysql_native_password      | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| mysql_old_password         | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| sha256_password            | ACTIVE   | AUTHENTICATION     | NULL             | GPL     |
| CSV                        | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MyISAM                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MRG_MYISAM                 | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| MEMORY                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| PERFORMANCE_SCHEMA         | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| ARCHIVE                    | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| BLACKHOLE                  | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| FEDERATED                  | DISABLED | STORAGE ENGINE     | NULL             | GPL     |
| InnoDB                     | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| INNODB_TRX                 | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCKS               | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_LOCK_WAITS          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP                 | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_RESET           | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM              | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMPMEM_RESET        | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_PER_INDEX       | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_CMP_PER_INDEX_RESET | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_PAGE         | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_PAGE_LRU     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_BUFFER_POOL_STATS   | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_METRICS             | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_DEFAULT_STOPWORD | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_DELETED          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_BEING_DELETED    | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_CONFIG           | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_INDEX_CACHE      | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_FT_INDEX_TABLE      | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLES          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESTATS      | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_INDEXES         | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_COLUMNS         | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FIELDS          | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN         | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_FOREIGN_COLS    | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_TABLESPACES     | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| INNODB_SYS_DATAFILES       | ACTIVE   | INFORMATION SCHEMA | NULL             | GPL     |
| partition                  | ACTIVE   | STORAGE ENGINE     | NULL             | GPL     |
| handlersocket              | ACTIVE   | DAEMON             | handlersocket.so | BSD     |
+----------------------------+----------+--------------------+------------------+---------+
43 rows in set (0.02 sec)

phpのhandlersocketモジュールをインストール

cd /usr/local/src/
curl -O https://php-handlersocket.googlecode.com/files/php-handlersocket-0.3.1.tar.gz
tar zxvf php-handlersocket-0.3.1.tar.gz
cd handlersocket/

phpize
./configure --disable-handlersocket-hsclient
make
make install

vi /etc/php.ini
extension=handlersocket.so

テスト

> CREATE TABLE `user` (
 `id` INT(10) NOT NULL AUTO_INCREMENT,
 `name` VARCHAR(255) NULL DEFAULT NULL,
 `birthday` DATE NULL DEFAULT NULL,
 `memo` VARCHAR(255) NULL DEFAULT NULL,
 PRIMARY KEY (`id`)
);

> insert into user values(null, 'test1', '1980/05/01', 'test1');
> insert into user values(null, 'test2', '1980/05/02', 'test2');

phpソースを書いて、実行してみる。

# vi handlertest.php
<?
$host = 'localhost';
$port = 9998;
$port_wr = 9999;
$dbname = 'test';
$table = 'user';
$column = 'user_id,name,birthday,memo';

// select
$hs = new HandlerSocket($host, $port);

$hs->openIndex(1, $dbname, $table, '', $column);
// select * from user where id >= 1 limit 2;
$retval = $hs->executeSingle(1, '>=', array(1), 2);

var_dump($retval);

# insert
# $hs = new HandlerSocket($host, $port_wr);
# $hs->openIndex(2, $dbname, $table, '', $column);
# $hs->executeInsert(2, [2,"test3","2001-01-01","test3"]);
?>

# php handlertest.php
array(2) {
  [0]=>
  array(4) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "test1"
    [2]=>
    string(10) "1980-05-01"
    [3]=>
    string(4) "test1"
  }
  [1]=>
  array(4) {
    [0]=>
    string(1) "2"
    [1]=>
    string(5) "test2"
    [2]=>
    string(10) "1980-05-02"
    [3]=>
    string(5) "test2"
  }
}

以上