`

hive将查询结果,直接导入到mysql

    博客分类:
  • hive
 
阅读更多
1.加入jar
add jar /setup/hive/lib/mysql-connector-java-5.1.25-bin.jar;
add jar /setup/hive/lib/hive_contrib.jar;
add jar /setup/hive/lib/hive-contrib-0.9.0.jar;
 
2.创建function
CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
3.查询并插入到mysql中
//数据库连接,用户名,密码,插入语句sql,参数值,查询sql
select dboutput('jdbc:mysql://localhost/hive_result','root','','INSERT INTO tab_user(id,name) VALUES (?,?)',id,name) from tab_user limit 100;
 
注意,hive_result数据库中,ab_user必须存在,否则插入不成功,但也不报错。。。
 
 
  • 大小: 38.3 KB
  • 大小: 13.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics