Load a mysql table to HDFS using Sqoop

[Target]

Load a mysql table to HDFS


[Environment]

Eucalyptus in cloud test;
1 cluster consist of node1, node2, node3 (all redhat6.2);
1 other machine node4 runs mysql services (centos6.2);
HDFS service running, Map-Reduce service running;


[Setup Mysql Service]

1.in node4

#Stop firewall

$ /etc/init.d/iptables stop
$ setenforce 0


#Install mysql and mysql server, 

#if yum not work, 
#set proxy "export http_proxy=proxy01.cd.intel.com:911"
$ yum list mysql
$ yum install mysql
$ yum list mysql-server
$ yum install mysql-server


#Start mysql service

#Create a Admin and try to login
$ /etc/init.d/mysqld start # or service mysqld start
$ mysqladmin -u root password 123456
$ mysql -u root -p
> hidden password


#Grant that we can use username:root, password:123456 to access mysql on node4 from any machine

$ sudo mysql -u root -p
#grant all on 数据库名.* to 用户名@'客户端IP地址' identified by '密码';
$ grant all on *.* to root@'%' identified by '123456'; 


2.in node3/node2/node1

#Try to access mysql service on node4
$ mysql -u root -h IP_Address_Of_Node4 -p


3.in node1/node2/node3/node4

#create demo table

$ create database hadoopguide;
$ create table mytable(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, design_comment VARCHAR(100));
$ INSERT INTO mytable VALUES (NULL, 'Connects two gizmos');
$ INSERT INTO mytable VALUES (NULL, NULL);
$ INSERT INTO mytable VALUES (NULL, 'Our flagship product');


[Using Sqoop Command, Load table to HDFS]

1.in node1/node2/node3

#load table from mysql to HDFS

$ sqoop import --connect jdbc:mysql://IP_Address_Of_Node1or2or3/hadoopguide --table mytable --username root --password 123456

#check on HDFS

$ hadoop fs -ls


[Some Useful Mysql Command]

show databases;
use databaseName;
show tables;
show columns from tableName; #查询表结构
select user(); #查询当前用户
select database(); #查询当前使用的数据库


[Trouble Shotting]

1.If Map-Reduce service is not start:

13/04/21 16:03:54 ERROR security.UserGroupInformation: PriviledgedActionException as:root (auth:SIMPLE) cause:java.net.ConnectException: Call to Ltwqzf25l/192.168.99.47:54311 failed on connection exception: java.net.ConnectException: Connection refused
13/04/21 16:03:54 ERROR tool.ImportTool: Encountered IOException running import job: java.net.ConnectException: Call to Ltwqzf25l/192.168.99.47:54311 failed on connection exception: java.net.ConnectException: Connection refused
        at org.apache.hadoop.ipc.Client.wrapException(Client.java:1177)
        at org.apache.hadoop.ipc.Client.call(Client.java:1153)
        at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:225)
        at org.apache.hadoop.mapred.$Proxy1.getProtocolVersion(Unknown Source)
        at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:396)
        at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:379)
        at org.apache.hadoop.mapred.JobClient.createRPCProxy(JobClient.java:522)
        at org.apache.hadoop.mapred.JobClient.init(JobClient.java:507)
        at org.apache.hadoop.mapred.JobClient.<init>(JobClient.java:490)

[reference]

1.http://kalashnicov.iteye.com/blog/669429

2.http://51hired.com/questions/3300/yum%E5%AE%89%E8%A3%85MySQL%E5%B9%B6%E8%AE%BE%E7%BD%AE%E5%AF%86%E7%A0%81

3.http://hi.baidu.com/thelongesturl/item/20efe1253c9512cba5275ab4

4.http://help.dedecms.com/install-use/server/2011/0803/969.html

5.http://coolmist.iteye.com/blog/136657


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值