| Forum Home > Bigdata Learnings( Hadoop, HBase,Hive and other bigdata technologies) > Sqoop : Import Data from MySql to HBase | ||
|---|---|---|
|
Site Owner Posts: 83 |
Following are the steps to import data from MySql to HBase using Sqoop:
1) Login to mysql as follows: mysql -h hostname -u root -p
2) Create Database in mysql mysql>CREATE DATABASE testhadoop; Also you can use some existing database
3)Grant all privileges to all users to database mysql>GRANT ALL PRIVILEGES ONtesthadoop.* TO '%'@'host-ip'; mysql>GRANT ALL PRIVILEGES ON testhadoop.* TO ''@'host-ip;
4) Create a table in database and insert some data in it. mysql>USE testhadoop; mysql>CREATE TABLE employee( empid INT, empname varchar(20), salray(int)); mysql>INSERT INTO employee VALUES(1,'emp1',15000);
5)For example , table contains following data : mysql> select * from employee; +-------+---------+--------+ | empid | empname | salary | +-------+---------+--------+ | 1 | emp1 | 10000 | | 2 | emp2 | 15000 | | 3 | emp3 | 20000 | +-------+---------+--------+
6) Copy the mysql-connector jar in $SQOOP_HOME/lib
7) Now , employee table from mysql can be imported to HBase using Sqoop as follows: $ $SQOOP_HOME/bin/sqoop import --hbase-create-table --hbase-table myemployee --column-family info --hbase-row-key empid --connect jdbc:mysql://host-ip/testhadoop --table employee -m 1 hbase-create-table : will create table if it does not exist in HBase, if the table is already there then no need to use it
Tags: Load data from mysql to HBase
| |
| ||