Most of the steps to use hive for data analysis are to use hive to export the statistical results to a local file or other Hive tables, import the local file to mysql or use sqoop to import the Hive table to mysql.
Today, my colleague recommended a method to directly import the statistical results to mysql using udf functions.
Step:
Hive> add jar/usr/lib/hive/lib/hive-contrib-0.9.0-cdh4.1.2.jar;
Added/usr/lib/hive/lib/hive-contrib-0.9.0-cdh4.1.2.jar to class path
Added resource:/usr/lib/hive/lib/hive-contrib-0.9.0-cdh4.1.2.jar
Hive> add jar/usr/share/java/mysql-connector-java-5.1.17.jar;
Added/usr/share/java/mysql-connector-java-5.1.17.jar to class path
Added resource:/usr/share/java/mysql-connector-java-5.1.17.jar
Hive> create temporary function dboutput AS 'org. apache. Hadoop. hive. contrib. genericudf. example. genericudfdboutput ';
Hive> select dboutput ('jdbc: mysql: // localhost/result', 'root', '123', 'insert INTO dc (code, size) VALUES (?,?) ', Code, size) from accesslog limit 10;
Note: The result is the mysql database name, And the dc is the dc field in the brackets of the table name dc (code, size) in the database result. values (?,?) The code corresponding to the value following the hive statistical result. size is the field in the hive table, and accesslog represents the table name in hive.
After performing the preceding steps, you can import the hive statistical results to the mysql database.