sqoop常用命令
2016-03-10 10:12
405 查看
sqoop常用命令
目录(?)[+]1、列出mysql数据库中的所有数据库
sqoop list-databases --connect jdbc:mysql://localhost:3306/ -username dyh -password 0000002、连接mysql并列出数据库中的表
sqoop list-tables --connect jdbc:mysql://localhost:3306/test --username dyh --password 0000003、将关系型数据的表结构复制到hive中
sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --table users --username dyh--password 000000 --hive-table users --fields-terminated-by "\0001" --lines-terminated-by "\n";
参数说明:
--fields-terminated-by "\0001" 是设置每列之间的分隔符,"\0001"是ASCII码中的1,它也是hive的默认行内分隔符, 而sqoop的默认行内分隔符为","
--lines-terminated-by "\n" 设置的是每行之间的分隔符,此处为换行符,也是默认的分隔符;
注意:只是复制表的结构,表中的内容没有复制
4、将数据从关系数据库导入文件到hive表中
sqoop import --connect jdbc:mysql://localhost:3306/test --username dyh --password 000000--table users --hive-import --hive-table users -m 2 --fields-terminated-by "\0001";
参数说明:
-m 2 表示由两个map作业执行;
--fields-terminated-by "\0001" 需同创建hive表时保持一致;
5、将hive中的表数据导入到mysql数据库表中
sqoop export --connect jdbc:mysql://192.168.20.118:3306/test --username dyh --password 000000--table users --export-dir /user/hive/warehouse/users/part-m-00000
--input-fields-terminated-by '\0001'
注意:
1、在进行导入之前,mysql中的表userst必须已经提起创建好了。
2、jdbc:mysql://192.168.20.118:3306/test中的IP地址改成localhost会报异常,具体见本人上一篇帖子
6、将数据从关系数据库导入文件到hive表中,--query 语句使用
sqoop import --append --connect jdbc:mysql://192.168.20.118:3306/test --username dyh --password 000000 --query "select id,age,name from userinfos where \$CONDITIONS" -m 1 --target-dir /user/hive/warehouse/userinfos2 --fields-terminated-by",";
7、将数据从关系数据库导入文件到hive表中,--columns --where 语句使用
sqoop import --append --connect jdbc:mysql://192.168.20.118:3306/test --username dyh --password 000000 --table userinfos --columns "id,age,name" --where "id > 3 and (age = 88 or age = 80)" -m 1 --target-dir /user/hive/warehouse/userinfos2--fields-terminated-by ",";
注意:--target-dir /user/hive/warehouse/userinfos2 可以用 --hive-import --hive-table userinfos2 进行替换
相关文章推荐
- JDK和Tomcat官网下载,包含各个历史版本
- Zabbix 监控某无法获取某主机信息记录
- Offscreen Rendering and Multisampling With OpenGL
- 技术实战:基于 MHA 方式实现 MySQL 的高可用
- rails 项目部署中 nginx 报错及解决方法
- 【linux】/dev/null与/dev/zero详解【转】
- Linux系统启动过程
- linux文件的权限说明
- ubuntu安装openssh-server 报依赖错误的解决过程
- docker学习笔记11:Dockerfile 指令 CMD介绍
- Linux用户(User)和用户组(Group)管理命令
- 《Linux总线、设备与驱动》USB设备发现机制
- linux tar.gz zip 解压缩 压缩命令
- 用浏览器管理 Docker
- Starting Tomcat v6.0 Server at localhost' has encountered a problem,Several ports (8005, 8080, 8009)
- Compile Sources 和 Copy Bundle Resources的区别
- Nginx配置
- Linux内核分析第三周学习总结:构造一个简单的Linux系统MenuOS
- centos下搭建cacti
- Linux_用户、组及权限管理