安裝 HTTP Plugin for MySQL

最近用 Xamarin 在開發 Android/iOS 的 App,

一般來說並不推薦直接在 App 上直接連結 MySQL 這類的資料庫,

這樣會有安全上的問題,

所以一般比較推薦的做法是透過 REST 或是 Web Service 的作法,

在手機中用類似網頁連線的方式和資料庫進行溝通,

之前的作法都是用類似 ServiceStack / Sandman / PHPRestSQL 這類軟體先做出資料庫的 REST 介面,

然後手機這端在透過 REST 操作資料庫

MySQL  <===> ServiceStack / Sandman / PHPRestSQL <=====> App

然而在即將推出的 MySQL 5.7 中多了一個新的 HTTP Plugin for MySQL

可以直接提供 REST 介面,

MySQL <=====> App

HTTP Plugin for MySQL 下載:

http://labs.mysql.com/

安裝的話只要將 libmyhttp.so 放到 /var/lib/mysql/plugin/ 下面

# cp libmyhttp.so /var/lib/mysql/plugin/

然後登入 mysql 畫面執行安裝指令就可以了,
安裝後可以透過 SHOW PLUGINS; 查看是否有安裝進去,
並透過 SELECT * FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME=’myhttp’\G; 查詢 plugin 的詳細訊息

# mysql -uroot -p

mysql> INSTALL PLUGIN myhttp SONAME 'libmyhttp.so';
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW PLUGINS;
+----------------------------+----------+--------------------+--------------+---------+
| Name                       | Status   | Type               | Library      | License |
+----------------------------+----------+--------------------+--------------+---------+
| binlog                     | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| mysql_native_password      | ACTIVE   | AUTHENTICATION     | NULL         | GPL     |
| sha256_password            | ACTIVE   | AUTHENTICATION     | NULL         | GPL     |
| CSV                        | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| MRG_MYISAM                 | ACTIVE   | 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_TEMP_TABLE_INFO     | 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     |
| MyISAM                     | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| MEMORY                     | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| BLACKHOLE                  | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| ARCHIVE                    | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| PERFORMANCE_SCHEMA         | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| FEDERATED                  | DISABLED | STORAGE ENGINE     | NULL         | GPL     |
| partition                  | ACTIVE   | STORAGE ENGINE     | NULL         | GPL     |
| myhttp                     | ACTIVE   | DAEMON             | libmyhttp.so | GPL     |
+----------------------------+----------+--------------------+--------------+---------+
43 rows in set (0.00 sec)

mysql> SELECT * FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='myhttp'\G;
*************************** 1. row ***************************
           PLUGIN_NAME: myhttp
        PLUGIN_VERSION: 1.0
         PLUGIN_STATUS: ACTIVE
           PLUGIN_TYPE: DAEMON
   PLUGIN_TYPE_VERSION: 50705.0
        PLUGIN_LIBRARY: libmyhttp.so
PLUGIN_LIBRARY_VERSION: 1.5
         PLUGIN_AUTHOR: Andrey Hristov, Ulf Wendel
    PLUGIN_DESCRIPTION: HTTP Plugin for MySQL
        PLUGIN_LICENSE: GPL
           LOAD_OPTION: ON
1 row in set (0.00 sec)

這個 HTTP Plugin 有提供三個 API 介面
http://127.0.0.1:8080/crud/db/

http://127.0.0.1:8080/doc/db/

http://127.0.0.1:8080/sql/db/

mysql