一 数据库与表

    • Mysql:
    • DB2:
      等待补充

    • Inceptor:

    1. scan complete in 2ms
    2. Connecting to jdbc:hive2://192.168.1.70:10000/
    3. 2016-03-22 08:33:48,094 INFO jdbc.Utils: Supplied authorities: 192.168.1.70:10000
    4. 2016-03-22 08:33:48,094 INFO jdbc.Utils: Resolved authority: 192.168.1.70:10000
    5. Connected to: Apache Hive (version 0.12.0-transwarp-tdh40)
    6. Driver: Hive JDBC (version 0.12.0-transwarp-tdh40)
    7. Transaction isolation: TRANSACTION_REPEATABLE_READ
    8. Beeline version 0.12.0-transwarp-tdh40 by Apache Hive
    9. 0: jdbc:hive2://192.168.1.70:10000/> show databases;
    10. +----------------+
    11. | database_name |
    12. +----------------+
    13. | default |
    14. +----------------+
    15. 1 row selected (2.282 seconds)
    16. 0: jdbc:hive2://192.168.1.70:10000/>
    17. 1 row selected (2.282 seconds)
    18. 0: jdbc:hive2://192.168.1.70:10000/> use default;
    19. No rows affected (0.068 seconds)
    20. 0: jdbc:hive2://192.168.1.70:10000/> show tables;
    21. +-----------+
    22. | tab_name |
    23. +-----------+
    24. +-----------+
    25. No rows selected (0.08 seconds)
    26. 0: jdbc:hive2://192.168.1.70:10000/>

    实验准备数据一 Pubs数据库

    1. 在Inceptor metastore节点服务器上安装sqoop服务
      1. yum install sqoop
    2. 由于Inceptor-SQL中metastore中已经安装了mysql,就不需要安装mysql了

    3. 将mysql-connector-java-5.1.38tar.gz驱动包先解压

    4. 从mysql————>HDFS上(import,将mysql中的db1数据库里面的表导入到/user/datadir,这里的datadir目录一定不要事先创建,不然会报错,语句执行的时候会自动创建目录的!最后一行的-m表示map成4个文件)

    1. sqoop import \
    2. --username chu888chu888 \
    3. --password skybar \
    4. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    5. --table titleauthor \
    6. --target-dir /user/chu888chu888/data/titleauthor -m 4
    7. sqoop import \
    8. --username chu888chu888 \
    9. --password skybar \
    10. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    11. --table authors \
    12. --target-dir /user/chu888chu888/data/authors -m 4
    13. sqoop import \
    14. --username chu888chu888 \
    15. --password skybar \
    16. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    17. --table authors \
    18. --target-dir /user/chu888chu888/data/employee -m 4
    19. sqoop import \
    20. --username chu888chu888 \
    21. --password skybar \
    22. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    23. --table discounts \
    24. --target-dir /user/chu888chu888/data/discounts -m 4
    25. sqoop import \
    26. --username chu888chu888 \
    27. --password skybar \
    28. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    29. --table jobs \
    30. --target-dir /user/chu888chu888/data/jobs -m 4
    31. sqoop import \
    32. --username chu888chu888 \
    33. --password skybar \
    34. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    35. --table pub_info \
    36. --target-dir /user/chu888chu888/data/pub_info -m 4
    37. sqoop import \
    38. --username chu888chu888 \
    39. --password skybar \
    40. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    41. --table publishers \
    42. --target-dir /user/chu888chu888/data/publishers -m 4
    43. 有一个问题如果表没有主键的话,就会导入不了.
    44. alter table roysched add roysched_id int unsigned not Null auto_increment primary key;
    45. sqoop import \
    46. --username chu888chu888 \
    47. --password skybar \
    48. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    49. --table roysched \
    50. --target-dir /user/chu888chu888/data/roysched -m 4
    51. sqoop import \
    52. --username chu888chu888 \
    53. --password skybar \
    54. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    55. --table sales \
    56. --target-dir /user/chu888chu888/data/sales -m 4
    57. sqoop import \
    58. --username chu888chu888 \
    59. --password skybar \
    60. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    61. --table stores \
    62. --target-dir /user/chu888chu888/data/stores -m 4
    63. sqoop import \
    64. --username chu888chu888 \
    65. --password skybar \
    66. --connect jdbc:mysql://192.168.1.178:3306/Pubs \
    67. --target-dir /user/chu888chu888/data/titles -m 4

    6 SQL SERVER导入的问题

    1. mysql> desc authors;
    2. +----------+-------------+------+-----+---------+-------+
    3. | Field | Type | Null | Key | Default | Extra |
    4. +----------+-------------+------+-----+---------+-------+
    5. | au_id | varchar(11) | NO | PRI | NULL | |
    6. | au_lname | varchar(40) | NO | MUL | NULL | |
    7. | au_fname | varchar(20) | NO | | NULL | |
    8. | phone | varchar(12) | NO | | UNKNOWN | |
    9. | city | varchar(20) | YES | | NULL | |
    10. | state | varchar(2) | YES | | NULL | |
    11. | zip | varchar(5) | YES | | NULL | |
    12. | contract | bit(1) | NO | | NULL | |
    13. +----------+-------------+------+-----+---------+-------+
    14. 9 rows in set (0.00 sec)
    15. create external table authors
    16. (
    17. au_id STRING,
    18. au_lname STRING,
    19. au_fname STRING,
    20. phone STRING,
    21. address STRING,
    22. city STRING,
    23. state STRING,
    24. zip STRING,
    25. contract STRING
    26. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/authors';
    27. mysql> desc discounts;
    28. +--------------+--------------+------+-----+---------+-------+
    29. | Field | Type | Null | Key | Default | Extra |
    30. +--------------+--------------+------+-----+---------+-------+
    31. | discounttype | varchar(40) | NO | | NULL | |
    32. | stor_id | varchar(4) | YES | | NULL | |
    33. | lowqty | smallint(6) | YES | | NULL | |
    34. | highqty | smallint(6) | YES | | NULL | |
    35. | discount | decimal(6,2) | NO | | NULL | |
    36. +--------------+--------------+------+-----+---------+-------+
    37. 5 rows in set (0.00 sec)
    38. create external table discounts
    39. (
    40. discounttype STRING,
    41. stor_id STRING,
    42. lowqty STRING,
    43. highqty STRING,
    44. discount STRING,
    45. discount_id STRING
    46. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/discounts';
    47. mysql> desc employee;
    48. +-----------+---------------------+------+-----+---------+-------+
    49. | Field | Type | Null | Key | Default | Extra |
    50. +-----------+---------------------+------+-----+---------+-------+
    51. | emp_id | varchar(9) | NO | PRI | NULL | |
    52. | fname | varchar(20) | NO | | NULL | |
    53. | minit | varchar(1) | YES | | NULL | |
    54. | lname | varchar(30) | NO | MUL | NULL | |
    55. | job_id | smallint(6) | NO | | 1 | |
    56. | job_lvl | tinyint(3) unsigned | YES | | 10 | |
    57. | pub_id | varchar(4) | NO | | 9952 | |
    58. | hire_date | date | YES | | NULL | |
    59. +-----------+---------------------+------+-----+---------+-------+
    60. 8 rows in set (0.00 sec)
    61. create external table employee
    62. (
    63. emp_id STRING,
    64. fname STRING,
    65. minit STRING,
    66. lname STRING,
    67. job_id STRING,
    68. job_lvl STRING,
    69. pub_id STRING,
    70. hire_date STRING
    71. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/employee';
    72. mysql> desc jobs;
    73. +----------+---------------------+------+-----+-----------------------------------------+----------------+
    74. | Field | Type | Null | Key | Default | Extra |
    75. +----------+---------------------+------+-----+-----------------------------------------+----------------+
    76. | job_id | smallint(6) | NO | PRI | NULL | auto_increment |
    77. | job_desc | varchar(50) | NO | | New Position - title not formalized yet | |
    78. | min_lvl | tinyint(3) unsigned | NO | | NULL | |
    79. | max_lvl | tinyint(3) unsigned | NO | | NULL | |
    80. +----------+---------------------+------+-----+-----------------------------------------+----------------+
    81. 4 rows in set (0.00 sec)
    82. create external table jobs
    83. (
    84. job_id STRING,
    85. job_desc STRING,
    86. min_lvl STRING,
    87. max_lvl STRING
    88. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/jobs';
    89. mysql> desc pub_info;
    90. +---------+------------+------+-----+---------+-------+
    91. | Field | Type | Null | Key | Default | Extra |
    92. +---------+------------+------+-----+---------+-------+
    93. | pub_id | varchar(4) | NO | PRI | NULL | |
    94. | logo | longblob | YES | | NULL | |
    95. | pr_info | longtext | YES | | NULL | |
    96. +---------+------------+------+-----+---------+-------+
    97. 3 rows in set (0.00 sec)
    98. create external table pub_info
    99. (
    100. pub_id STRING,
    101. logo STRING,
    102. pr_info STRING
    103. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/pub_info';
    104. mysql> desc publishers;
    105. +----------+-------------+------+-----+---------+-------+
    106. | Field | Type | Null | Key | Default | Extra |
    107. +----------+-------------+------+-----+---------+-------+
    108. | pub_id | varchar(4) | NO | PRI | NULL | |
    109. | pub_name | varchar(40) | YES | | NULL | |
    110. | city | varchar(20) | YES | | NULL | |
    111. | state | varchar(2) | YES | | NULL | |
    112. +----------+-------------+------+-----+---------+-------+
    113. 5 rows in set (0.00 sec)
    114. create external table publishers
    115. pub_id STRING,
    116. pub_name STRING,
    117. city STRING,
    118. state STRING,
    119. country STRING
    120. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/publishers';
    121. mysql> desc roysched;
    122. +----------+------------+------+-----+---------+-------+
    123. | Field | Type | Null | Key | Default | Extra |
    124. +----------+------------+------+-----+---------+-------+
    125. | title_id | varchar(6) | NO | MUL | NULL | |
    126. | lorange | int(11) | YES | | NULL | |
    127. | hirange | int(11) | YES | | NULL | |
    128. | royalty | int(11) | YES | | NULL | |
    129. +----------+------------+------+-----+---------+-------+
    130. 4 rows in set (0.00 sec)
    131. create external table roysched
    132. (
    133. title_id STRING,
    134. lorange STRING,
    135. hirange STRING,
    136. royalty STRING
    137. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/roysched';
    138. mysql> desc sales;
    139. +----------+-------------+------+-----+---------+-------+
    140. | Field | Type | Null | Key | Default | Extra |
    141. +----------+-------------+------+-----+---------+-------+
    142. | stor_id | varchar(4) | NO | PRI | NULL | |
    143. | ord_num | varchar(20) | NO | PRI | NULL | |
    144. | ord_date | date | YES | | NULL | |
    145. | qty | smallint(6) | NO | | NULL | |
    146. | payterms | varchar(12) | NO | | NULL | |
    147. | title_id | varchar(6) | NO | PRI | NULL | |
    148. +----------+-------------+------+-----+---------+-------+
    149. 6 rows in set (0.00 sec)
    150. create external table sales
    151. (
    152. stor_id STRING,
    153. ord_num STRING,
    154. ord_date STRING,
    155. qty STRING,
    156. title_id STRING
    157. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/sales';
    158. mysql> desc stores;
    159. +--------------+-------------+------+-----+---------+-------+
    160. | Field | Type | Null | Key | Default | Extra |
    161. +--------------+-------------+------+-----+---------+-------+
    162. | stor_id | varchar(4) | NO | PRI | NULL | |
    163. | stor_name | varchar(40) | YES | | NULL | |
    164. | stor_address | varchar(40) | YES | | NULL | |
    165. | city | varchar(20) | YES | | NULL | |
    166. | state | varchar(2) | YES | | NULL | |
    167. | zip | varchar(5) | YES | | NULL | |
    168. +--------------+-------------+------+-----+---------+-------+
    169. 6 rows in set (0.01 sec)
    170. create external table stores
    171. (
    172. stor_id STRING,
    173. stor_name STRING,
    174. stor_address STRING,
    175. city STRING,
    176. zip STRING
    177. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/stores';
    178. mysql> desc titleauthor;
    179. +------------+---------------------+------+-----+---------+-------+
    180. | Field | Type | Null | Key | Default | Extra |
    181. +------------+---------------------+------+-----+---------+-------+
    182. | au_id | varchar(11) | NO | PRI | NULL | |
    183. | title_id | varchar(6) | NO | PRI | NULL | |
    184. | au_ord | tinyint(3) unsigned | YES | | NULL | |
    185. | royaltyper | int(11) | YES | | NULL | |
    186. +------------+---------------------+------+-----+---------+-------+
    187. 4 rows in set (0.00 sec)
    188. create external table titleauthor
    189. (
    190. au_id STRING,
    191. title_id STRING,
    192. au_ord TinyInt,
    193. royaltyper INT
    194. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/titleauthor';
    195. mysql> desc titles;
    196. +-----------+---------------+------+-----+-----------+-------+
    197. | Field | Type | Null | Key | Default | Extra |
    198. +-----------+---------------+------+-----+-----------+-------+
    199. | title_id | varchar(6) | NO | PRI | NULL | |
    200. | title | varchar(80) | NO | MUL | NULL | |
    201. | type | varchar(12) | NO | | UNDECIDED | |
    202. | pub_id | varchar(4) | YES | | NULL | |
    203. | price | decimal(19,4) | YES | | NULL | |
    204. | advance | decimal(19,4) | YES | | NULL | |
    205. | royalty | int(11) | YES | | NULL | |
    206. | ytd_sales | int(11) | YES | | NULL | |
    207. | notes | varchar(200) | YES | | NULL | |
    208. | pubdate | datetime | NO | | NULL | |
    209. +-----------+---------------+------+-----+-----------+-------+
    210. 10 rows in set (0.00 sec)
    211. create external table titles
    212. (
    213. title_id STRING,
    214. title STRING,
    215. type STRING,
    216. pub_id STRING,
    217. price STRING,
    218. advance STRING,
    219. royalty STRING,
    220. ytd_sales STRING,
    221. notes STRING,
    222. )row format delimited fields terminated by ',' location '/user/chu888chu888/data/titles';