注意!!!ODBC版本过新会导致Doris BE服务宕机,目前测试下来 8.0.26及 8.0.28版本均有问题,降为 8.0.11后未出现问题,其余版本请自行测试!
1.安装ODBC驱动 首先我们安装unixODBC驱动
sudo wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.4.tar.gz tar -xvzf unixODBC-2.3.4.tar.gz cd unixODBC-2.3.4/ sudo ./configure –prefix=/usr/local/unixODBC-2.3.7 –includedir=/usr/include –libdir=/usr/lib -bindir=/usr/bin –sysconfdir=/etc make sudo make install
安装成功后,unixODBC所需的头文件都被安装到了/usr/inlucde下,编译好的库文件安装到了/usr/lib下,与unixODBC相关的可执行文件安装到了/usr/bin下,配置文件放到了/etc下。
验证安装是否成功 odbcinst -j
2.安装Mysql ODBC驱动
从mysql 站点下载对应的驱动
https://dev.mysql.com/downloads/connector/odbc/
mysql-connector-odbc-8.0.11-linux-glibc2.12-x86-64bit.tar.gz
1 2 tar zxvf mysql-connector-odbc-8 .0 .11 -linux-glibc2.12 -x86-64 bit.tar.gzmv mysql-connector-odbc-8 .0 .11 -linux-glibc2.12 -x86-64 bit mysql-connectort-odbc-8 .0 .11
注册Mysql驱动,进入mysql-connectort-odbc-8.0.11/bin路径下
1 2 ./myodbc-installer -a -d -n "MySQL ODBC 8.0.11 Unicode Driver" -t "Driver=/opt/software/mysql-connector-odbc-8.0.11/lib/libmyodbc8w.so" ./myodbc-installer -a -d -n "MySQL ODBC 8.0.11 ANSI Driver" -t "Driver=/opt/software/mysql-connector-odbc-8.0.11/lib/libmyodbc8a.so"
然后查看是否注册成功 ./myodbc-installer -d -l
3.验证通过ODBC访问Mysql
去配置ODBC访问Mysql的参数
编辑/etc/odbc.ini文件,加入下面的内容,将信息替换成你自己的
1 2 3 4 5 6 7 8 9 [mysql] Description = Data source MySQLDriver = MySQL ODBC 8.0 .28 Unicode DriverServer = localhostHost = localhostDatabase = test_dbPort = 3306 User = test_userPassword = 123456
然后我们通过:
isql -v mysql测试能否通过ODBC连接Mysql
4.在BE节点的conf/odbcinst.ini,添加我们的刚才注册的8.0.11的ODBC驱动
1 2 3 4 [MySQL ODBC 8.0.11] Description = ODBC for MySQLDriver =/opt/software/mysql-connector-odbc-8.0 .11 /lib/libmyodbc8w.soFileUsage = 1
5.在Doris创建外部表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 DROP TABLE IF EXISTS test.external_ods_esc_goods;CREATE TABLE test.external_ods_esc_goods ( id varchar (128 ) NOT NULL COMMENT '主键ID' , goods_id varchar (128 ) NOT NULL COMMENT '商品ID' , expire_date datetime DEFAULT NULL COMMENT '有效期截止日' , spu_outer_id varchar (1024 ) DEFAULT NULL COMMENT '外部商品ID' , company_id varchar (128 ) NOT NULL COMMENT '公司ID' , outer_id varchar (128 ) DEFAULT NULL COMMENT '平台ID' , update_time datetime DEFAULT NULL COMMENT '更新时间' , creator varchar (128 ) DEFAULT NULL COMMENT '创建人' , modifier varchar (128 ) DEFAULT NULL COMMENT '修改人' , create_time datetime COMMENT '创建时间' )ENGINE=ODBC PROPERTIES ( "host"="xx.xxx.xx.xx", "port"="3307", "user"="test", "password"="123456", "database"="test", "table"="goods", "driver"="MySQL ODBC 8.0.11 Unicode Driver", "odbc_type"="mysql" );
或者创建外部resource
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #drop RESOURCE isc_mysql_odbc_goods_oc; CREATE EXTERNAL RESOURCE isc_mysql_odbc_goods_oc PROPERTIES ( "type" = "odbc_catalog", "host"="xx.xx.xx.xx", "port"="3306", "user"="xxxx", "password"="xxxxxx", "driver"="MySQL ODBC 8.0 Unicode Driver", "odbc_type"="mysql" );DROP TABLE IF EXISTS test.external_ods_esc_goods;CREATE TABLE test.external_ods_esc_goods ( id varchar (128 ) NOT NULL COMMENT '主键ID' , goods_id varchar (128 ) NOT NULL COMMENT '商品ID' , expire_date datetime DEFAULT NULL COMMENT '有效期截止日' , spu_outer_id varchar (1024 ) DEFAULT NULL COMMENT '外部商品ID' , company_id varchar (128 ) NOT NULL COMMENT '公司ID' , outer_id varchar (128 ) DEFAULT NULL COMMENT '平台ID' , update_time datetime DEFAULT NULL COMMENT '更新时间' , creator varchar (128 ) DEFAULT NULL COMMENT '创建人' , modifier varchar (128 ) DEFAULT NULL COMMENT '修改人' , create_time datetime COMMENT '创建时间' )ENGINE=ODBC PROPERTIES ( "odbc_catalog_resource" = "isc_mysql_odbc", "database" = "test", "table" = "goods" );
验证查询
1 select * from test.external_ods_esc_goods
6.创建Doris表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 DROP TABLE IF EXISTS ods.ods_esc_goods;CREATE TABLE ods.ods_esc_goods ( id varchar (128 ) NOT NULL COMMENT '主键ID' , goods_id varchar (128 ) NOT NULL COMMENT '商品ID' , expire_date datetime DEFAULT NULL COMMENT '有效期截止日' , spu_outer_id varchar (1024 ) DEFAULT NULL COMMENT '外部商品ID' , company_id varchar (128 ) NOT NULL COMMENT '公司ID' , outer_id varchar (128 ) DEFAULT NULL COMMENT '平台ID' , update_time datetime DEFAULT NULL COMMENT '更新时间' , creator varchar (128 ) DEFAULT NULL COMMENT '创建人' , modifier varchar (128 ) DEFAULT NULL COMMENT '修改人' , create_time datetime COMMENT '创建时间' ,INDEX INDEX_GOODS_ID (goods_id),INDEX INDEX_COM_ID (company_id) ,INDEX INDEX_SPU_OUTER_ID (spu_outer_id) )UNIQUE KEY (id,goods_id)COMMENT '商品扩展信息表' DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ( "replication_num" = "3" );
7.从外部表同步数据到Doris
insert into ods.ods_esc_goods select * from test.external_ods_esc_goods
查看doris是否有数据
select * from ods.ods_esc_goods