一、編碼基本設置java
因爲hdfs使用的是utf-8的編碼格式,因此無論是從mysql導入,仍是直接上傳文件,編碼格式必須是utf-8,不然就會出現亂碼,全部有幾個編碼設置點要注意:mysql
(1)、源數據mysql須要設置my.cnf配置文件 (不一樣版本可能設置不同) sql
[client] 數據庫
default-character-set=utf8 app
/*[mysqld]*/ oop
character-set-server=utf8 編碼
(2)、源數據庫(database編碼確認設置)server
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |utf-8
若是不是以上格式,使用該指令設置,變換不一樣參數便可:set character_set_server=utf8;get
(3)讀取源數據的jdbc鏈接加上utf-8編碼
sqoop import --connect jdbc:mysql://10.0.13.116:3306/test?characterEncoding=UTF-8 --username hive --password for3edc4rfv --table driver --delete-target-dir --hive-overwrite --fields-terminated-by "," --target-dir /apps/hive/warehouse/t_driver
(4)hive的jdbc鏈接也設置utf-8
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</value>
</property>
二、執行sqoop指令的權限
因爲sqoop須要操做hdfs,因此須要使用hdfs帳號執行sqoop指令,不然要報無權限錯誤;