业务背景
利用Sqoop对MySQL进行查询、添加、删除等操作。
业务实现
select操作:
sqoop eval \--connect jdbc:mysql://127.0.0.1:3306/market \--username admin \--password 123456 \--query "select end_user_id, category_id, score, last_bought_date, days_left, update_time from market.PERIOD_RECOMMEND limit 10"
执行结果如下:
[pms@yhd-jqHadoop39 /home/pms/workspace/ouyangyewei/data]$sqoop eval \> --connect jdbc:mysql://10.0.2.54:3307/market \> --username marketuser \> --password 123456 \> --query "select end_user_id, category_id, score from market.PERIOD_RECOMMEND limit 10" ----------------------------------------------------------------------------------| END_USER_ID | CATEGORY_ID | SCORE ----------------------------------------------------------------------------------| 1020 | 6639 |0.03765381553445836| 1180 | 6008 |0.49232472007320505 | 1180 | 6638 |0.12863038975524008 ----------------------------------------------------------------------------------
删除操作:
sqoop eval \--connect jdbc:mysql://127.0.0.1:3306/market \--username admin \--password 123456 \--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操作。