利用sqoop对mysql执行DML操作

业务背景

利用Sqoop对MySQL进行查询、添加、删除等操作。

业务实现

select操作:

sqoop eval \
--connect jdbc:mysql://127.0.0.1:3306/market \
--username admin \
--password \
--query "select end_user_id, category_id, score, last_bought_date, days_left, update_time
from market.PERIOD_RECOMMEND limit "

执行结果如下:

[pms@yhd-jqHadoop39 /home/pms/workspace/ouyangyewei/data]
$sqoop eval \
> --connect jdbc:mysql://10.0.2.54:3307/market \
> --username marketuser \
> --password \
> --query "select end_user_id, category_id, score from market.PERIOD_RECOMMEND limit " ----------------------------------------------------------------------------------
| END_USER_ID | CATEGORY_ID | SCORE
----------------------------------------------------------------------------------
| | |0.03765381553445836
| | |0.49232472007320505
| | |0.12863038975524008
----------------------------------------------------------------------------------

删除操作:

sqoop eval \
--connect jdbc:mysql://127.0.0.1:3306/market \
--username admin \
--password \
--query "delete from PERIOD_RECOMMEND where update_time < '2015-06-01'"

其他操作操作:

sqoop eval \
--connect jdbc:mysql://127.0.0.1:3306/market \
--username admin \
--password 123456 \
--query "call procedure_clear_aaa()"

利用sqoop eval,只需要在参数--query中指定sql语句即可对mysql执行DML操作。

上一篇:剑指 Offer II 109. 开密码锁


下一篇:jmeter之关联