Hadoop应用实验:Sqoop安装与配置

========================================================

1. 安装MySQL,添加测试数据(本次培训以MySQL数据库的映射为例)

=======================================================

yum -y install mysql-server (-y参数表示安装过程所有的选项选择yes)

 

#启动mysql服务

service mysqld start

 

#登录mysql服务器,首次启动root无密码

mysql -uroot

  #登录后为root设置密码123456

  set password for root@localhost=password('123456');

  exit

 

mysql -uroot -p123456

  grant all privileges on *.* to root@'%' identified by '123456' with grant option;

  exit

(后来在执行数据导入时,提示没有权限访问表,查询百度后此处多执行一句

grant all privileges on *.* to root@node01 identified by '123456' with grant option;)

 

#修改mysql字符编码支持

vim /etc/my.cnf

  [mysqld]

  default-character-set=utf8

  [client]

  default-character-set=utf8

#创建原始mysql表格,添加示例数据,为导入sqoop做准备

mysql -root -p123456

  show databases;

  use test;

  show tables;

  create table t1(id int auto_increment primary key, name varchar(36));

  show tables;

  insert into t1(name) values('zhangsan');

  select * from t1

 

==============================

2. 安装sqoop,练习数据导入导出

==============================

tar xf *.tat -C /opt/tools

cd /opt/tools

ll

mv sq.. sqoop

 

cp mysql-connector /opt/tools/sqoop/lib

环境变量加入

export SQOOP

 

(导入数据)

sqoop import --connect jdbc:mysql://node01:3306/test --username root --password 123456 --table t1 --target-dir /user/root/3

在浏览器browse user/root/3

或者hdfs dfs -get /user/root/3/part-m-00000

rm -f part-m-00000

hdfs dfs -get /user/root/3/part-m-00000

cat part-m-00000

 

(导出到mysql)

进入mysql创建表t2,准备接收从sqoop导出的数据

  create table t2(id int auto_increment primary key, name varchar(36))

sqoop export --connect jdbc:mysql://node01:3306/test --username root --password 123456 --export-dir /user/root/3 --table t2 --input-fileds-tertminted-by ',' --columns="id,name"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值