J'KYO
No pains,no gains.
 

步骤一:

hive> add jar /setup/hive/lib/mysql-connector-java-5.1.25-bin.jar;
hive> add jar /usr/lib/hive/lib/hive-contrib-0.9.0-cdh4.1.2.jar;

步骤二:

hive> CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.Hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';

 


步骤三:

hive> select dboutput('jdbc:mysql://localhost/result','root','123456','INSERT INTO dc(code,size) VALUES (?,?)',code,size) from accesslog limit 10;

 


参考资料:

1、hive表直接入库本地mysql,用udf从将hive的查询结果直接写入mysql数据库中 
http://blog.sina.com.cn/s/blog_13088c10a0102wxit.html

2、hive将查询结果,直接导入到mysql 
http://jxauwxj.iteye.com/blog/1947616

posted on 2018-04-26 17:25  J'KYO  阅读(3870)  评论(0编辑  收藏  举报