sqoop实现mysql与hdfs数据迁移
2016-06-13 19:42
393 查看
sqoop安装:安装在一台节点上就可以了。
1.上传sqoop
2.安装和配置
在添加sqoop到环境变量
将数据库连接驱动拷贝到$SQOOP_HOME/lib里
3.使用
第一类:数据库中的数据导入到HDFS上
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --columns 'id, account, income, expenses'
指定输出路径、指定数据分隔符
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --target-dir '/sqoop/td' --fields-terminated-by '\t'
指定Map数量 -m
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --target-dir '/sqoop/td1' --fields-terminated-by '\t' -m 2
增加where条件, 注意:条件必须用引号引起来
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --where 'id>3' --target-dir '/sqoop/td2'
增加query语句(使用 \ 将语句换行)
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 \
--query 'SELECT * FROM trade_detail where id > 2 AND $CONDITIONS' --split-by trade_detail.id --target-dir '/sqoop/td3'
注意:如果使用--query这个命令的时候,需要注意的是where后面的参数,AND $CONDITIONS这个参数必须加上
而且存在单引号与双引号的区别,如果--query后面使用的是双引号,那么需要在$CONDITIONS前加上\即\$CONDITIONS
如果设置map数量为1个时即-m 1,不用加上--split-by ${tablename.column},否则需要加上
第二类:将HDFS上的数据导出到数据库中(不要忘记指定分隔符)
sqoop export --connect jdbc:mysql://192.168.8.120:3306/itcast --username root --password 123 --export-dir '/td3' --table td_bak -m 1 --fields-terminated-by ','
4.配置mysql远程连接
GRANT ALL PRIVILEGES ON itcast.* TO 'root'@'192.168.1.201' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES
1.上传sqoop
2.安装和配置
在添加sqoop到环境变量
将数据库连接驱动拷贝到$SQOOP_HOME/lib里
3.使用
第一类:数据库中的数据导入到HDFS上
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --columns 'id, account, income, expenses'
指定输出路径、指定数据分隔符
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --target-dir '/sqoop/td' --fields-terminated-by '\t'
指定Map数量 -m
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --target-dir '/sqoop/td1' --fields-terminated-by '\t' -m 2
增加where条件, 注意:条件必须用引号引起来
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 --table trade_detail --where 'id>3' --target-dir '/sqoop/td2'
增加query语句(使用 \ 将语句换行)
sqoop import --connect jdbc:mysql://192.168.1.10:3306/itcast --username root --password 123 \
--query 'SELECT * FROM trade_detail where id > 2 AND $CONDITIONS' --split-by trade_detail.id --target-dir '/sqoop/td3'
注意:如果使用--query这个命令的时候,需要注意的是where后面的参数,AND $CONDITIONS这个参数必须加上
而且存在单引号与双引号的区别,如果--query后面使用的是双引号,那么需要在$CONDITIONS前加上\即\$CONDITIONS
如果设置map数量为1个时即-m 1,不用加上--split-by ${tablename.column},否则需要加上
第二类:将HDFS上的数据导出到数据库中(不要忘记指定分隔符)
sqoop export --connect jdbc:mysql://192.168.8.120:3306/itcast --username root --password 123 --export-dir '/td3' --table td_bak -m 1 --fields-terminated-by ','
4.配置mysql远程连接
GRANT ALL PRIVILEGES ON itcast.* TO 'root'@'192.168.1.201' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES
相关文章推荐
- [置顶] MySQL server has gone away 问题的解决方法
- 浅谈SQL Server中的三种物理连接操作(Nested Loop Join、Merge Join、Hash Join)
- 浅谈SQL Server中的三种物理连接操作(Nested Loop Join、Merge Join、Hash Join)
- 6 SQLite与ContentProvider
- 问题-FireDAC连接Sqlite3提示“unable to open database file”
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- oracle 11g 安装以及工具PLsql developer配置
- mysql error 1290 hy000:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statemen' 解决方案
- 设置PL/SQL Developer自动提交事务
- mysql性能调优和架构设计读书笔记
- 4000 PLSQL Developer建表时注释(COMMENT)中文乱码的解决方案(Windows)
- mac 配置openfile+ MySQL搭建即时聊天服务器
- 运维角度浅谈MySQL数据库优化
- golang 远程连接mssql 2000
- Mysql+IIS+三层架构创建网站遇到的过程总结
- 使用MHA对mysql主从架构中的主节点做高可用
- Listview(黑名单)&sqlite(sql+api SqliteDataBase SqltieOpenHelper)
- hadoop操作mysql
- Hadoop Hive sql语法详解
- 使用PL/SQL Developer 登陆 oracle 11g 64位数据库