我是靠谱客的博主 务实钻石,最近开发中收集的这篇文章主要介绍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"

最后

以上就是务实钻石为你收集整理的Hadoop应用实验:Sqoop安装与配置的全部内容,希望文章能够帮你解决Hadoop应用实验:Sqoop安装与配置所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(85)

评论列表共有 0 条评论

立即
投稿
返回
顶部