一、將數(shù)據(jù)從mysql導(dǎo)入到hdfs上庸毫。
sqoop import /
--connect jdbc:mysql://10.110.22.238/test_sqoop / # mysql數(shù)據(jù)庫所在得到節(jié)點(diǎn)ip及數(shù)據(jù)庫名
--username root / # 數(shù)據(jù)庫用戶名
--password bigdata / # 數(shù)據(jù)庫密碼
--table books / # 所要導(dǎo)出數(shù)據(jù)的表名
--target-dir /user/root/user_data / # 指定導(dǎo)入到hdfs上的哪個(gè)路徑范舀,sqoop自動(dòng)創(chuàng)建此目錄
--columns "stud_id,stud_name" / # 抽取數(shù)據(jù)表中的指定列
--m 1
命令
- 結(jié)果出現(xiàn)錯(cuò)誤:
ERROR tool.ImportTool: Error during import: No primary key could be found for table books. Please specify one with --split-by or perform a sequential import with '-m 1'.
錯(cuò)誤
- 結(jié)果還是有錯(cuò)誤:
ERROR tool.ImportTool: Encountered IOException running import job: org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode="/user/root/.staging":hdfs:hdfs:drwxr-xr-x
原來是在hdfs下沒有/user/root這個(gè)目錄合是,自己新建目錄,并且必須將此目錄的所屬用戶和用戶組設(shè)為root:root锭环。
hadoop fs -mkdir /user/root
hadoop fs -chown -R root:root /user/root
修改完后在執(zhí)行即可成功聪全。
導(dǎo)入到hdfs上的數(shù)據(jù)
mysql中的數(shù)據(jù)