1. 程式人生 > >大數據(Hive的MetaStore切換及其Hive的語法細節)

大數據(Hive的MetaStore切換及其Hive的語法細節)

ant bin 自啟 tor focus sql命令 cli explore .sql

大數據課程第六天


MetaStore
1. MetaStore在Hive中是非常重要的一個概念,通過MetaStoreHive存儲HDFS與表的對應關系,MetaStore通過RDB進行數據的存儲.
2. MetaStore默認是通過Derby數據庫,進行元數據存儲的.
3. 如果用Derby充當默認的MetaStore,Hive只能以一個Client進行訪問

Hive中MetaStore的切換

把默認的Derby切換成其他的RDB(MySQL)
  1. 切換的步驟

    1. 安裝MySQL數據庫
       yum install -y mysql-server
       service mysqld start #啟動mysql服務
       chkconfig mysqld on  #自啟動
       修改root用戶密碼
       
    /usr/bin/mysqladmin -u root password ‘new-password‘ 2. 打開mysql遠端訪問權限 use mysql grant all privileges on *.* to root@‘%‘ identified by "1234456"; flush privileges; delete from user where host != ‘%‘ service mysqld restart 3. 修改hive的配置 hive-site.xml <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://
    hadoop4:3306/metastore?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property> 4. 上傳mysql的驅動jar 到 hive_home/lib
    5.測試 啟動hive,建庫:hive> create database if not exists mydb; hive> use mydb; mydb下建表: hive> create table if not exists t_user( > id int, > name string)row format delimited fields terminated by ‘\t‘; OK 本地導入數據 hive> load data local inpath ‘/root/test‘ into table t_user; 查詢: hive> select * from t_user; OK 1 lhc 2 aaa 3 bbb 4 ccc Time taken: 10.678 seconds, Fetched: 4 row(s) 網頁也可查看對應存儲路徑:http://hadoop1:50070/explorer.html#/user/hive/warehouse/mydb.db
Hive的語法細節
  • Hive相關的配置文件

    hive-default.xml
    ?
    hive-site.xml
    <!--顯示數據庫名-->
    <property>
          <name>hive.cli.print.current.db</name>
          <value>true</value>
     </property>
     <!--顯示查詢表的列名-->
     <property>
          <name>hive.cli.print.header</name>
          <value>true</value>
    </property>
    也可以通過shell或者hive命令行修改
    bin/hive --hiveconf hive.cli.print.header false
    ?
    hive>set hive.cli.print.header
    hive>set hive.cli.print.header=true
    ?
  • Hive的啟動參數

    #啟動
    1. bin/hive
    #啟動hive時,修改hive的配置項
    2. bin/hive --hiveconf hive.cli.print.header false
    #查看幫助文檔
    3. bin/hive -help 查看hive的幫助信息
    #啟動hive 同時指定數據庫
    4. bin/hive --database baizhi_140
    #啟動hive 同時執行命令
    5. bin/hive -e ‘show databases‘
       bin/hive --database baizhi_140 -e ‘show tables‘
       >:覆蓋原來文件             >>:追加到源文件
       bin/hive --database baizhi_140 -e ‘select * from t_user‘  >> /root/result
    #啟動hive,同時執行命令文件(sql命令放在sql文件裏)
    6. bin/hive -f /opt/datas/hive.sql    
       bin/hive --database baizhi_140 -f /root/hive.sql   >> /root/result
  • 數據庫

  • 導入數據

  • 導出數據

  • SQL語句

大數據(Hive的MetaStore切換及其Hive的語法細節)