当前位置: 首页 > 文档资料 > 大数据实验手册 >

第七章 Sqoop - 4.Sqooq2综合案例

优质
小牛编辑
124浏览
2023-12-01

数据库基本操作命令

1 选择数据库命令

  • Mysql:

现在我用一个例子讲解sqoop2的具体使用方法,数据准备,有一个mysql的表叫worker,里面有三条数据,我们要将其导入hadoop,这是建表语句

  1. 登录方式:
  2. #直接本地登录 root:123456
  3. #mysql -u root -p
  4. mysql> show databases;
  5. +--------------------+
  6. | Database |
  7. +--------------------+
  8. | information_schema |
  9. | hive |
  10. | mysql |
  11. | performance_schema |
  12. +--------------------+
  13. 4 rows in set (0.02 sec)
  14. mysql> create database chu888chu888;
  15. Query OK, 1 row affected (0.00 sec)
  16. mysql> use chu888chu888;
  17. Database changed
  18. mysql> CREATE TABLE `workers` (
  19. -> `id` int(11) NOT NULL AUTO_INCREMENT,
  20. -> `name` varchar(20) NOT NULL,
  21. -> PRIMARY KEY (`id`)
  22. -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  23. Query OK, 0 rows affected (0.00 sec)
  24. mysql> insert into workers (name) VALUES (NULL, 1 row affected (0.00 sec)
  25. mysql> insert into workers (name) VALUES (NULL, 1 row affected (0.00 sec)
  26. mysql> insert into workers (name) VALUES (NULL, 1 row affected (0.00 sec)

2. 导入数据

  1. $sqoop2-shell
  2. sqoop:000> show connector
  3. 16/08/09 13:35:05 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
  4. +------------------------+---------+------------------------------------------------------------+----------------------+
  5. | Name | Version | Class | Supported Directions |
  6. +------------------------+---------+------------------------------------------------------------+----------------------+
  7. | oracle-jdbc-connector | 1.99.7 | org.apache.sqoop.connector.jdbc.oracle.OracleJdbcConnector | FROM/TO |
  8. | sftp-connector | 1.99.7 | org.apache.sqoop.connector.sftp.SftpConnector | TO |
  9. | kafka-connector | 1.99.7 | org.apache.sqoop.connector.kafka.KafkaConnector | TO |
  10. | kite-connector | 1.99.7 | org.apache.sqoop.connector.kite.KiteConnector | FROM/TO |
  11. | ftp-connector | 1.99.7 | org.apache.sqoop.connector.ftp.FtpConnector | TO |
  12. | hdfs-connector | 1.99.7 | org.apache.sqoop.connector.hdfs.HdfsConnector | FROM/TO |
  13. | generic-jdbc-connector | 1.99.7 | org.apache.sqoop.connector.jdbc.GenericJdbcConnector | FROM/TO |
  14. +------------------------+---------+------------------------------------------------------------+----------------------+