安裝和配置 HandlerSocket 的方法如下:
安裝 HandlerSocket 擴展
git clone https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git
cd HandlerSocket-Plugin-for-MySQL
./autogen.sh && ./configure && make && make install
配置 MySQL Server
sudo vi /etc/mysql/my.cnf
[mysqld]
部分:# 啟用 HandlerSocket 插件
handlersocket_address = localhost
handlersocket_port = 9998
handlersocket_port_wr = 9999
handlersocket_threads = 16
handlersocket_threads_wr = 1
handlersocket_socket = /tmp/mysql.sock
handlersocket_max_open_tables = 128
handlersocket_max_tmp_tables = 32
handlersocket_readsize = 64k
handlersocket_keysize = 1024
handlersocket_worker_threads = 16
handlersocket_index_threads = 16
handlersocket_accept_threads = 16
handlersocket_debug = false
sudo service mysql restart
測試 HandlerSocket
mysql -u root -p
CREATE DATABASE test;
USE test;
CREATE TABLE users (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255));
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
SELECT id, name, email FROM users WHERE id = 1;
這將返回類似 [1,"John Doe","john@example.com"]
的結果,表示查詢成功。這樣,你就成功安裝和配置了 HandlerSocket。你可以通過 HandlerSocket 進行高性能的讀取和更新操作,比傳統的 SQL 查詢更快速。