暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Doris直连MySQL实践笔记

原创 数据库管理员陆美芳 2024-08-30
1035

1、下载MySQL的驱动

根据Doris官网推荐,从这里下载驱动包

2、上传MySQL驱动包

在Doris安装目录下创建jdbc_drivers目录,创建好可以看到如下效果:

[root@localhost apache-doris]# ll
总用量 0
drwxr-xr-x. 11 root root 163 6月  23 12:43 be
drwxr-xr-x.  3 root root  32 6月  23 12:43 extensions
drwxr-xr-x. 14 root root 260 7月  17 13:35 fe
drwxr-xr-x.  2 root root  42 8月  30 16:23 jdbc_drivers
[root@localhost apache-doris]# pwd
/opt/apache-doris

然后把驱动包放入/opt/apache-doris/jdbc_drivers/,放入后查看到如下信息:

[root@localhost apache-doris]# cd jdbc_drivers/
[root@localhost jdbc_drivers]# ll
总用量 2460
-rw-r--r--. 1 root root 2515447 8月  30 15:31 mysql-connector-j-8.0.31.jar

3、修改Doris配置文件

修改的是be.conf和fe.conf的参数,原来是注释的,把注释去掉,并改成如下内容:

# Default dirs to put jdbc drivers,default value is ${DORIS_HOME}/jdbc_drivers
jdbc_drivers_dir = /opt/apache-doris/jdbc_drivers

4、重启fe和be

重启fe

[root@crmdb2 fe]# ./bin/stop_fe.sh 
waiting fe to stop, pid: 28435
stop java, and remove pid file. 
[root@crmdb2 fe]# ./bin/start_fe.sh --daemon

重启be

[root@crmdb2 be]# ./bin/stop_be.sh 
waiting be to stop, pid: 30978
stop doris_be, and remove pid file. 
[root@crmdb2 be]# ./bin/start_be.sh --daemon

5、创建catalog

用MySQL客户端连接doris,并执行如下命令:

CREATE CATALOG mysql PROPERTIES (
    "type"="jdbc",
    "user"="账号",
    "password"="密码",
    "jdbc_url" = "jdbc:mysql://MySQL的IP地址:3306",
    "driver_url" = "mysql-connector-j-8.0.31.jar",
    "driver_class" = "com.mysql.cj.jdbc.Driver"
);

其中账号密码和IP都改成实际的,driver_url的值就是/opt/apache-doris/jdbc_drivers下面的文件名,数据库的端口如果指定非默认端口3306则修改成指定端口。

6、访问外部资源验证

mysql> show catalogs;
+-----------+-------------+----------+-----------+-------------------------+----------------+------------------------+
| CatalogId | CatalogName | Type     | IsCurrent | CreateTime              | LastUpdateTime | Comment                |
+-----------+-------------+----------+-----------+-------------------------+----------------+------------------------+
|         0 | internal    | internal | yes       | UNRECORDED              | NULL           | Doris internal catalog |
|    515133 | mysql       | jdbc     |           | 2024-08-30 16:18:22.987 | NULL           |                        |
+-----------+-------------+----------+-----------+-------------------------+----------------+------------------------+
2 rows in set (0.01 sec)

mysql> switch mysql;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| casdoor            |
| dataease           |
| information_ads    |
| information_dw     |
| information_ods    |
| information_schema |
| information_tdm    |
| jsp_db             |
| mysql              |
| test               |
+--------------------+
10 rows in set (0.48 sec)

mysql> select count(*) from dataease.area;
+----------+
| count(*) |
+----------+
|     3413 |
+----------+
1 row in set (0.64 sec)

上面是切换catalog的访问方式,还可以不切换,直接用catalog名称.库名.表名来访问:
select * from mysql.dataease.area;
到此,就可以在Doris里面直接查询MySQL的数据了!!!

最后修改时间:2024-08-30 17:06:30
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论