Sqoop installation: Installed on a node on the can.
1. Upload Sqoop
2. Install and configure add SQOOP to environment variable copy the database connection driver to $sqoop_home/lib 3. Use the first class: Data in the database is imported into HDFs SQOOP import--connect jdbc:mysql://192.16 8.1.10:3306/itcast--username root--password 123--table trade_detail--columns ' ID, account, income, expenses ' Specify the output Out path, specified data delimiter sqoop import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123--table trade_d Etail--target-dir '/sqoop/td '--fields-terminated-by ' \ t ' specify map number-m sqoop import--connect jdbc:mysql://192.168.1 .10:3306/itcast--username Root--password 123--table trade_detail--target-dir '/sqoop/td1 '--fields-terminated-by ' \ t '-M 2
Add where condition, note: The condition must be enclosed in quotation marks sqoop import--connect jdbc:mysql://192.168.1.10:3306/itcast-- Username root--password 123 --table trade_detail--where ' id>3 '--target-dir '/sqoop/td2 '
Add a query statement (use \ Wrap statement) sqoop import--connect jdbc:mysql://192.168.1.10:3306/itcast--username Root--password 123 \--query ' SELECT * from Trade_detail where ID > 2 and $CONDITIONS '--split-by trade_detail.id--ta Rget-dir '/sqoop/td3 ' Note: If you use the--query command, you need to be aware of the arguments behind the where, and $CONDITIONS This parameter must be added There is the difference between single and double quotes, if--query is followed by double quotes, you need to precede $conditions with \ \ $CONDITIONS If you set the number of maps to 1-m 1, do not add--split-by ${tablename.column}, or you need to add Second class: The data on HDFs is exported to the database (do not forget to specify the delimiter) sqoop Export--connect jdbc:mysql://192.168.8.120:3306/itcast--username root--password 123--export-dir '/td3 '--table td_ Bak-m 1--fields-terminated-by ', ' 4. Configure MySQL remote connection grant all privileges on itcast.* to ' root ' @ ' 192.168.1.201 ' Identified by ' 123 ' with GRANT OPTION; flush privileges; grant all privileges on * * to ' root ' @ '% ' identified by ' 123 ' with GRANT OPTION; flush Privileges
Use of Sqoop