Running Environment CentOS 5.6 Hadoop hive
Sqoop is a tool developed by clouder for hadoop technology support to import and export data between relational databases, hdfs, and hive.
Read more: Sqoop configuration and installation
1. Install sqoop first. If you are using the clouder distribution version, it will be very simple.
# Yum install sqoop
If the official version is used
# Cd/etc/yum. repos. d
# Wget http://archive.cloudera.com/RedHat/cdh/cloudera-cdh3.repo
# Yum-y install sqoop
Sqoop installation is complete.
2. Use sqoop
First copy the mysql-connector-java-5.1.16-bin.jar file to the/usr/lib/sqoop/lib folder
List all database commands in the mysql database
# Sqoop list-databases -- connect jdbc: mysql: // localhost: 3306/-- username root -- password 123456
Connect to mysql and List table commands in the database
# Sqoop list-tables -- connect jdbc: mysql: // localhost: 3306/test -- username root -- password 123456
In the command, test is the name of the test Database in mysql database, username password is the user password of mysql database respectively.
Copy the table structure of relational data to hive
Sqoop create-hive-table -- connect jdbc: mysql: // localhost: 3306/test -- table username -- username root -- password 123456 -- hive-table test
Here, -- table username is the table in database test in mysql -- hive-table test is the name of the table created in hive.