sqoop 是 Hadoop 和关系数据库服务器之间传送数据的工具。主要用于在hive和关系型数据库间进行数据的传递,可以将一个关系型数据库中的数据导进到Hadoop的HDFS中,也可以将HDFS的数据导进到关系型数据库中。
核心的功能有两个:
导入、迁入
导出、迁出
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/sqoop/
首先将文件放进Linux,然后使用命令tar解压sqoop
[root@master dev]# tar -zxvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
将sqoop-1.4.7.bin__hadoop-2.6.0改为sqoop
[root@master dev]# mv sqoop-1.4.7.bin__hadoop-2.6.0 sqoop
在home目录下创建apps文件夹。
[root@master dev]# mkdir -p /home/apps
将sqoop文件夹放入apps中。
[root@master dev]# mv sqoop /home/apps
使用vi命令修改系统环境变量文件
[root@master dev]# vi /etc/profile
添加以下环境变量
export SQOOP_HOME=/home/apps/sqoop
export PATH=$PATH:$SQOOP_HOME/bin
使添加的环境变量立即生效
[root@master dev]# source /etc/profile
Sqoop的配置文件在conf文件夹里面
[root@master dev]# cd /home/apps/sqoop/conf
[root@master conf]# ll
total 28
-rw-rw-r--. 1 centos centos 3895 Dec 19 2017 oraoop-site-template.xml
-rw-rw-r--. 1 centos centos 1404 Dec 19 2017 sqoop-env-template.cmd
-rwxr-xr-x. 1 centos centos 1345 Dec 19 2017 sqoop-env-template.sh
-rw-rw-r--. 1 centos centos 6044 Dec 19 2017 sqoop-site-template.xml
-rw-rw-r--. 1 centos centos 6044 Dec 19 2017 sqoop-site.xml
使用mv将文件名改为sqoop-env.sh和vi命令写入文件
[root@master conf]# mv sqoop-env-template.sh sqoop-env.sh
[root@master conf]# vi sqoop-env.sh
修改你的已经安装了的Hadoop组件,如果没有安装的就注释。
#Set path to where bin/hadoop is available
export HADOOP_COMMON_HOME=/home/hadoop/hadoop-2.9.2
#Set path to where hadoop-*-core.jar is available
export HADOOP_MAPRED_HOME=/home/hadoop/hadoop-2.9.2
#set the path to where bin/hbase is available
export HBASE_HOME=/home/apps/habase
#Set the path to where bin/hive is available
export HIVE_HOME=/home/apps/hive
#Set the path for where zookeper config dir is
export ZOOCFGDIR=/home/apps/zookeeper
为什么在sqoop-env.sh 文件中会要求分别进行 common和mapreduce的配置呢???
在apache的hadoop的安装中;四大组件都是安装在同一个hadoop_home中的
但是在CDH, HDP中, 这些组件都是可选的。
在安装hadoop的时候,可以选择性的只安装HDFS或者YARN,
CDH,HDP在安装hadoop的时候,会把HDFS和MapReduce有可能分别安装在不同的地方
[root@master dev]# mv mysql-connector-java-5.1.48.jar /home/apps/sqoop/lib
注:如果启动失败可能是MySQL驱动包版本问题
验证sqoop安装是否成功
[root@master dev]# sqoop-version
首先我们可以使用sqoop help命令来查看sqoop支持哪些命令
[root@master dev]# sqoop help
21/01/15 18:53:02 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
usage: sqoop COMMAND [ARGS]
Available commands:
codegen Generate code to interact with database records
create-hive-table Import a table definition into Hive
eval Evaluate a SQL statement and display the results
export Export an HDFS directory to a database table
help List available commands
import Import a table from a database to HDFS
import-all-tables Import tables from a database to HDFS
import-mainframe Import datasets from a mainframe server to HDFS
job Work with saved jobs
list-databases List available databases on a server
list-tables List available tables in a database
merge Merge results of incremental imports
metastore Run a standalone Sqoop metastore
version Display version information
See 'sqoop help COMMAND' for information on a specific command.
[root@master dev]#
如果不知道使用方式,可以使用sqoop help import 的命令 来查看某条具体命令的使用方式,
[root@master dev]# sqoop help import
查看MySQL中有哪些数据库
[root@master dev]# sqoop list-databases --connect jdbc:mysql://192.168.1.121:3306/ --username root --password 123456789
21/01/15 19:01:38 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
21/01/15 19:01:38 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
21/01/15 19:01:38 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
Fri Jan 15 19:01:38 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
information_schema
hive
mysql
performance_schema
sys
[root@master dev]#
结语:大数据Hadoop笔记sqoop安装与配置