Hive is a client that uses a similar SQL statement to operate a file stored in HDFs, a data warehouse that needs to be used in conjunction with a relational database, and hive comes with a relational database derby, but it's not officially recommended, and we use MySQL here. The function of relational database is to make the data structure of HDFS, and to correspond the structure and map.
MySQL is used to store mapping relationships, and HDFs is used to store data
First, install MySQL
Slightly
Second, hive installation
1) Extract Hive
tar -zxvf apache-hive-1.0. 1-bin. tar. gz
2) Generate Hive-site.xml
CP Hive-default.xml.template Hive-site.xml
3) Create the specified path and user name
① creates the specified path, replacing the value System:java.io.tmpdir in Hive-site.xml
mkdir /home/whu/hadoop-hive/hive-1.0. 1-bin/iotmp
Replace the value of System:java.io.tmpdir in Hive-site.xml
② Create the specified user name folder under the folder above
cd/home/whu/hadoop-hive/hive-1.0. 1-bin/iotmpmkdir WHU
Replace the value of System:user.name in Hive-site.xml
4) Create a database in MySQL
Mysql-u root-p
Create a specified database
Create DATABASE hive;
5) Modify Hive-site.xml
① Modifying a specified relational database
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql:/ /localhost:3306/hive</value></property>
② Modifying the driver
<property> <name>javax.jdo.option.ConnectionDriverName</name> <value> Com.mysql.jdbc.driver</value></property>
③ Modifying the user name of the connection database
<property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</ Value></property>
Note: Because my test environment hive and MySQL are installed on a machine, there is no set root for remote login, if MySQL and hive are not on a single machine, you need to configure root or other users to log on remotely
Grant all on * * to [email protected]'%'root';
④ Modifying the password of the connection database
<property> <name>javax.jdo.option.ConnectionPassword</name> <value>root</ Value></property>
6) Copy the MySQL driver to the Lib directory of Hive
CP mysql-connector-java-5.1. -bin.jar /home/whu/soft/apache-hive/lib
Note: If the MySQL drive is not in the correct version, it will cause the deletion of the table to fail, so it is more appropriate to release the MySQL drive.
7) Start Hive
Add hive to an environment variable first
Export Hadoop_home=/home/whu/soft/apache-hive
Export Path= $HADOOP _home:bin
Make environment variables effective
Source/etc/profile
Start Hive
Hive
Third, Hive simple use
1) Display Database
show databases;
2) Display Data sheet
Use database;show tables;
3) Create a database
Create Database basename;
4) Delete Database
basename;
5) Create a table
' /001 ' stored as textfile;
6) Delete Table
if exists tablename;
7) Upload Data
' Path ' into table tablename;
8) inserting data
INSERT into TABLE tablename1 [PARTITION (Partcol1=val1, Partcol2=val2 ...)] select_statement1 from From_statement;
Hive Installation and use