MySQL HandlerSocket插件安装配置教程(2)_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2745 | 回复: 0   主题: MySQL HandlerSocket插件安装配置教程(2)        下一篇 
ab19890824
注册用户
等级:少尉
经验:351
发帖:92
精华:0
注册:2011-11-21
状态:离线
发送短消息息给ab19890824 加好友    发送短消息息给ab19890824 发消息
发表于: IP:您无权察看 2014-11-17 10:44:49 | [全部帖] [楼主帖] 楼主

[root@iredmail HandlerSocket-Plugin-for-MySQL]# mysql -uroot -p
mysql> install plugin handlersocket soname 'handlersocket.so';
ERROR 1126 (HY000): Can't open shared library '/usr/local/webserver/mysql5520/lib/plugin/handlersocket.so' (errno: 2 cannot open shared object file: No such file or directory)


说明:这里提示没有找到handlersocket.so扩展文件,请查看扩展文件是否存在。

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


至此,HandlerSocket插件安装完毕。

重启mysql服务:

复制代码 代码如下:

[root@iredmail HandlerSocket-Plugin-for-MySQL]# service mysqld restart


3、HandlerSocket状态测试:

也可以通过查询刚配置的端口是否已经被MySQL占用来确认是否安装成功:

复制代码 代码如下:

[root@iredmail HandlerSocket-Plugin-for-MySQL]# lsof -i -P | grep mysqld
mysqld    26871 mysql   11u  IPv4  72467      0t0  TCP *:9998 (LISTEN)
mysqld    26871 mysql   29u  IPv4  72469      0t0  TCP *:9999 (LISTEN)
mysqld    26871 mysql   31u  IPv4  72474      0t0  TCP *:3306 (LISTEN)
Tips:If ports 9998 and 9999 don't show up.  Make sure SELinux is not running.


三、安装配置 php-handlersocket 扩展模块:

1、安装php-handlersocket扩展

复制代码 代码如下:

[root@iredmail opt]# wget
[root@iredmail opt]# tar -zxvf php-handlersocket-0.3.1.tar.gz
[root@iredmail opt]# cd handlersocket/
[root@iredmail handlersocket]# /usr/local/webserver/php5318/bin/phpize
[root@iredmail handlersocket]# ./configure --with-php-config=/usr/local/webserver/php5318/bin/php-config


./configure可加参数:

Tips:If you get error:
configure: error: Can't find hsclient  headers,please install libhsclient first,Or ./configure--disable-handlersocket-hsclient --with-php-config=/usr/local/webserver/php5318/bin/php-config use native type.


复制代码 代码如下:

[root@iredmail handlersocket]#make && make install
A successful install will have created handlersocket.so and put it into the PHP extensions directory. You'll need to and adjust php.ini and add an extension=handlersocket.so line before you can use the extension.


复制代码 代码如下:

[root@iredmail handlersocket]# vi /usr/local/webserver/php5318/etc/php.ini
extension=handlersocket.so


至此php扩展安装完成,放问php.info页面,我们可以看到已经成功加载了handlersocket扩展

2、php-handlersocket 使用示例:

复制代码 代码如下:

/*
 * String  $host:MySQL ip;
 * String  $port:handlersocket插件的监听端口,它有两个端口可选:一个用于读、一个用于写
 */
$hs = new HandlerSocket($host, $port);


打开一个数据表:

/*
 * Int       $index:这个数字相当于文件操作里的句柄,HandlerSocket的所有其他方法都会依据这个数字来操作由这个   openIndex打开的表,
 * String  $dbname:库名
 * String  $table:表名
 * String  $key:表的“主键”(HandlerSocket::PRIMARY)或“索引名”作为搜索关键字段,这就是说表必须有主键或索引
 *                 个人理解:要被当做where条件的key字段,这样可以认为handlersocket只有一个where条件
 * String  $column:'column1,column2' 所打开表的字段(以逗号隔开),就是说$table表的其他字段不会被操作
 */
$hs->openIndex($index, $dbname, $table, $key, $column);


查询:

/*
 * Int     $index: openIndex()所用的$index
 * String  $operation:openIndex方法中指定的$key字段所用的操作符,目前支持'=', '>=', '< =', '>',and '< ';可以理解为where条件
 * Array   $value
 * Int       $number(默认是1):获取结果的最大条数;相当于SQL中limit的第二个参数
 * Int     $skip(默认是0):跳过去几条;相当于SQL中limit的第一个参数
 */
$retval = $hs->executeSingle($index, $operation, $value, $number, $skip);


插入(注意:此处的openIndex要用$port_wr,即读写端口):

/*
 * Int     $index: openIndex()所用的$index
 * Array   $arr:数字元素数与openIndex的$column相同
 */
$retval = $hs->executeInsert($index, $arr);


删除(注意:此处的openIndex要用$port_wr,即读写端口):

/*
 * Int     $index: openIndex()所用的$index
 * String  $operation:openIndex方法中指定的$key字段所用的操作符,目前支持'=', '>=', '< =', '>',and '< ';可以理解为where条件
 * Array   $value
 * Int     $number(默认是1):获取结果的最大条数;相当于SQL中limit的第二个参数
 * Int     $skip(默认是0):跳过去几条;相当于SQL中limit的第一个参数
 */
$retval = $hs->executeDelete($index, $operation, $value, $number, $skip);


更新(注意:此处的openIndex要用$port_wr,即读写端口):

/*
 * Int     $index: openIndex()所用的$index
 * String  $operation:openIndex方法中指定的$key字段所用的操作符,目前支持'=', '>=', '< =', '>',and '< ';可以理解为where条件
 * Array   $value
 * Int       $number(默认是1):获取结果的最大条数;相当于SQL中limit的第二个参数
 * Int     $skip(默认是0):跳过去几条;相当于SQL中limit的第一个参数
 */
$retval = $hs->executeUpdate($index, $operation, $value, $number, $skip);
Example:


测试库 hstestdb,测试表hstesttbl:

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论