Hive入門+示例
阿新 • • 發佈:2021-08-05
1、安裝mysql5.7
(1)安裝步驟:centos7 下安裝 mysql5.7 - 亞萌 - 部落格園 (cnblogs.com)
(2)映象中已有
2、進入MySQL
(1)注意與hive-site.xml裡的mysql
jdbc:mysql://hadoop000:3306/hadoop_hive?createDatabaseIfNotExist=true
指定mysql,相當於在hadoop000這臺機器上的3306埠,3306是mysql資料庫的預設埠號,指向hadoop_hive資料庫,
(2)進入MySQL
注意與hive-site.xml裡的javax.jdo.option.ConnectionUserName、ConnectionPassword對應上
使用者名稱是root,密碼是root
show後,資料庫是預設的三個:information_schema、mysql、performance_schema
[hadoop@hadoop000 ~]$ cd software/ [hadoop@hadoop000 software]$ mysql -uroot -proot
mysql> show databases;
(3)啟動hive
注意以後beeline和hiveserver2需要配合使用
[hadoop@hadoop000 bin]$ pwd /home/hadoop/app/hive-1.1.0-cdh5.15.1/bin [hadoop@hadoop000 bin]$ hive
(4)在hive裡建立測試資料庫
hive> create database testzhang_db;
建立結束後,會在mysql> show databases; 後出現第四個資料庫hadoop_hive。
hadoop_hive裡存放的是元資料資訊。其中有20多張tables,是hive為我們建立的。
mysql> use hadoop_hive;
mysql> show tables;
檢視DBS,即資料庫的資訊。是預設的hive資料庫
hadoop000:8020是hadoop路徑
/user/hive/warehouse是hive預設的路徑
mysql> select* from DBS \G;
[hadoop@hadoop000 ~]$ hadoop fs -ls /user/hive/warehouse
(5)準備資料
將 helloworld.txt變成hive裡的表。
[hadoop@hadoop000 data]$ vi helloworld.txt
1 zhangsan 2 lisi 3 wangwu
[hadoop@hadoop000 data]$ pwd
/home/hadoop/data
(6)在test_db中建立表,將資料載入到表中,使用sql統計資料
hive> use test_db; hive> show tables; hive> creat table helloworld(id int, name string) ROW FORMAT DELTMITED FIELDS TERMINATED BY '\t';
hive> show tables;
hive> select * from helloworld;
hive> load data local inpath '/home/hadoop/data/helloworld.txt' overwrite into table helloworld;
hive> select * from helloworld;
hive> select count(1) from helloworld;