--
1 2 |
# apt install mariadb-plugin-spider # wget https://github.com/xiezhenye/mysql-plugin-spider-engine/raw/master/src/scripts/install_spider.sql |
安裝 Spider 存儲引擎
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# mysql -u root -p < install_spider.sql @have_spider_plugin := 1 1 @have_spider_i_s_alloc_mem_plugin := 1 1 @have_spider_direct_sql_udf := 1 1 @have_spider_bg_direct_sql_udf := 1 1 @have_spider_ping_table_udf := 1 1 @have_spider_copy_tables_udf := 1 1 @have_spider_flush_table_mon_cache_udf := 1 1 |
查詢 SPIDER 存儲引擎是否支援
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# mysql -e 'SELECT engine, support, transactions, xa FROM information_schema.engines;' +--------------------+---------+--------------+------+ | engine | support | transactions | xa | +--------------------+---------+--------------+------+ | SPIDER | YES | YES | NO | | MRG_MyISAM | YES | NO | NO | | MEMORY | YES | NO | NO | | Aria | YES | NO | NO | | MyISAM | YES | NO | NO | | SEQUENCE | YES | YES | NO | | InnoDB | DEFAULT | YES | YES | | PERFORMANCE_SCHEMA | YES | NO | NO | | CSV | YES | NO | NO | +--------------------+---------+--------------+------+ 9 rows in set (0.000 sec) |
--
設定
172.16.1.175 - Spider 主機
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CREATE SERVER backend1 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '172.16.1.170', DATABASE 'test', USER 'spider', PASSWORD 'spider', PORT 3306 ); CREATE SERVER backend2 FOREIGN DATA WRAPPER mysql OPTIONS( HOST '172.16.1.173', DATABASE 'test', USER 'spider', PASSWORD 'spider', PORT 3306 ); |
更新
1 |
FLUSH TABLES; |
建立分表規則
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
create table opportunities ( id int, accountName varchar(20), name varchar(128), owner varchar(7), amount decimal(10,2), closeDate date, stageName varchar(11), primary key (id), key (accountName) ) engine=spider COMMENT='wrapper "mysql", table "opportunities"' PARTITION BY HASH (id) ( PARTITION pt1 COMMENT = 'srv "backend1"', PARTITION pt2 COMMENT = 'srv "backend2"' ) ; |
172.16.1.170 - backend1
1 2 3 4 5 6 7 8 9 10 11 |
create table opportunities ( id int, accountName varchar(20), name varchar(128), owner varchar(7), amount decimal(10,2), closeDate date, stageName varchar(11), primary key (id), key (accountName) ) engine=InnoDB; |
172.16.1.173 - backend2
1 2 3 4 5 6 7 8 9 10 11 |
create table opportunities ( id int, accountName varchar(20), name varchar(128), owner varchar(7), amount decimal(10,2), closeDate date, stageName varchar(11), primary key (id), key (accountName) ) engine=InnoDB; |
從 Spider 主機執行資料庫讀寫,
--
刪除
1 2 |
DROP SERVER backend1; DROP SERVER backend2; |
--
Error 1429: Unable to connect to foreign data source
1 |
FLUSH TABLES; |
--
735 total views, 1 views today