CentOS 5.6下利用Sqoop將hive資料匯入匯出資料到MySQL

來源:互聯網
上載者:User

運行環境  CentOS 5.6   Hadoop  hive

sqoop是讓hadoop支援人員的clouder公司開發的一個在關聯式資料庫和hdfs,hive之間資料匯入匯出的一個工具

相關閱讀:Sqoop配置安裝

1  首先安裝sqoop,如果你使用的是clouder分發版的話就非常簡單 

   # yum install sqoop

  如果用官方版本的話

   # cd /etc/yum.repos.d

   # wget http://archive.cloudera.com/RedHat/cdh/cloudera-cdh3.repo

   # yum -y install sqoop

   sqoop就會安裝完成

2  使用sqoop

   首先將mysql-connector-java-5.1.16-bin.jar檔案複製到/usr/lib/sqoop/lib檔案夾下

   列出mysql資料庫中的所有資料庫命令

  #  sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root --password 123456

   串連mysql並列出資料庫中的表命令

   # sqoop list-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456

   命令中的test為mysql資料庫中的test資料庫名稱  username password分別為mysql資料庫的使用者密碼


 將關係型資料的表結構複製到hive中
 sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --table username --username root --password 123456 --hive-table test
其中 --table username為mysql中的資料庫test中的表   --hive-table test 為hive中建立的表名稱

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.