sqoop命令举例

来源:互联网 发布:linuxmysql源码安装 编辑:程序博客网 时间:2024/06/05 09:44
1)列出mysql数据库中的所有数据库
sqoop list-databases –connect jdbc:mysql://localhost:3306/ –username root –password 123456
2)连接mysql并列出test数据库中的表
sqoop list-tables –connect jdbc:mysql://localhost:3306/test –username root –password 123456
命令中的test为mysql数据库中的test数据库名称 username password分别为mysql数据库的用户密码
3)将关系型数据的表结构复制到hive中,只是复制表的结构,表中的内容没有复制过去。
sqoop create-hive-table –connect jdbc:mysql://localhost:3306/test
–table sqoop_test –username root –password 123456 –hive-table
test
其中 –table sqoop_test为mysql中的数据库test中的表 –hive-table
test 为hive中新建的表名称
4)从关系数据库导入文件到hive中
sqoop import –connect jdbc:mysql://localhost:3306/zxtest –username
root –password 123456 –table sqoop_test –hive-import –hive-table
s_test -m 1
5)将hive中的表数据导入到mysql中,在进行导入之前,mysql中的表
hive_test必须已经提起创建好了。
sqoop export –connect jdbc:mysql://localhost:3306/zxtest –username
root –password root –table hive_test –export-dir
/user/hive/warehouse/new_test_partition/dt=2012-03-05
6)从数据库导出表的数据到HDFS上文件
./sqoop import –connect
jdbc:mysql://10.28.168.109:3306/compression –username=hadoop
–password=123456 –table HADOOP_USER_INFO -m 1 –target-dir
/user/test
7)从数据库增量导入表数据到hdfs中
./sqoop import –connect jdbc:mysql://10.28.168.109:3306/compression
–username=hadoop –password=123456 –table HADOOP_USER_INFO -m 1
–target-dir /user/test  –check-column id –incremental append
–last-value 3
0 0
原创粉丝点击