步驟一:
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