CREATE EXTERNAL WEB TABLE testtable ( 字段定义 ) EXECUTE 'mysql -hhost -uroot -ppassword -s -e "SELECT * FROM dbname.tablesname"' ON MASTER FORMAT 'TEXT'
上边是最终实现方法。下面简单说下实现依据
官方文档有写:
CREATE [READABLE] EXTERNAL WEB TABLE table_name ( column_name data_type [, ...] | LIKE other_table ) LOCATION ('http://webhost[:port]/path/file' [, ...]) | EXECUTE 'command' [ON ALL | MASTER | number_of_segments | HOST ['segment_hostname'] | SEGMENT segment_id ] FORMAT 'TEXT' [( [HEADER] [DELIMITER [AS] 'delimiter' | 'OFF'] [NULL [AS] 'null string'] [ESCAPE [AS] 'escape' | 'OFF'] [NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF'] [FILL MISSING FIELDS] )] | 'CSV' [( [HEADER] [QUOTE [AS] 'quote'] [DELIMITER [AS] 'delimiter'] [NULL [AS] 'null string'] [FORCE NOT NULL column [, ...]] [ESCAPE [AS] 'escape'] [NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF'] [FILL MISSING FIELDS] )] | 'CUSTOM' (Formatter=<formatter specifications>) [ ENCODING 'encoding' ] [ [LOG ERRORS] SEGMENT REJECT LIMIT count [ROWS | PERCENT] ]
剔除无用语法:
CREATE EXTERNAL WEB TABLE table_name ( column_name data_type [, ...] ) EXECUTE 'command' ON MASTER FORMAT 'TEXT'
分隔符封闭符可以根据需要调整,最后根据业务调整为文章一开始那样的命令。