[root@master ~]# ls
ac.sh 模板
anaconda-ks.cfg 视频
apache-hive-1.2.1-bin.tar.gz 图片
dump.rdb 文档
initial-setup-ks.cfg 下载
mysql57-community-release-el7-10.noarch.rpm 音乐
公共 桌面
[root@master ~]# mv apache-hive-1.2.1-bin.tar.gz /usr/local/soft/packages/
[root@master ~]# ls
ac.sh 公共 下载
anaconda-ks.cfg 模板 音乐
dump.rdb 视频 桌面
initial-setup-ks.cfg 图片
mysql57-community-release-el7-10.noarch.rpm 文档
[root@master ~]# cd /usr/local/soft/packages/
[root@master packages]# ls
apache-hive-1.2.1-bin.tar.gz redis-6.2.6.tar.gz
hadoop-2.7.6.tar.gz zookeeper-3.4.6.tar.gz
[root@master packages]# tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /usr/local/soft
root@master packages]# cd ..
[root@master soft]# ls
0?? jars shell
A?? jdk1.8.0_171 shell01
apache-hive-1.2.1-bin packages show
data redis test.txt
hadoop-2.7.6 redis-6.2.6 zookeeper-3.4.6
[root@master soft]# mv apache-hive-1.2.1-bin/ hive-1.2.1
[root@master soft]# ls
0?? hadoop-2.7.6 jdk1.8.0_171 redis-6.2.6 show
A?? hive-1.2.1 packages shell test.txt
data jars redis shell01 zookeeper-3.4.6
[root@master soft]# cd hive-1.2.1/
[root@master hive-1.2.1]# ls
bin examples lib NOTICE RELEASE_NOTES.txt
conf hcatalog LICENSE README.txt scripts
[root@master hive-1.2.1]# pwd
/usr/local/soft/hive-1.2.1
[root@master hive-1.2.1]# vim /etc/profile
[root@master hive-1.2.1]# source /etc/profile
[root@master hive-1.2.1]# hi
history hive-config.sh
hive hiveserver2
[root@master hive-1.2.1]# ls
bin examples lib NOTICE RELEASE_NOTES.txt
conf hcatalog LICENSE README.txt scripts
[root@master hive-1.2.1]# cd scripts/
[root@master scripts]# ls
metastore
[root@master scripts]# cd metastore/
[root@master metastore]# ls
upgrade
[root@master metastore]# cd upgrade/
[root@master upgrade]# ls
derby mssql mysql oracle postgres
[root@master upgrade]# cd mysql/
[root@master hive-1.2.1]# cd conf/
[root@master conf]# ls
beeline-log4j.properties.template
hive-default.xml.template
hive-env.sh.template
hive-exec-log4j.properties.template
hive-log4j.properties.template
ivysettings.xml
[root@master conf]# cp hive-default.xml.template hive-site.xml
[root@master conf]# cp hive-env.sh.template hive-env.sh
[root@master conf]# ls
beeline-log4j.properties.template
hive-default.xml.template
hive-env.sh
hive-env.sh.template
hive-exec-log4j.properties.template
hive-log4j.properties.template
hive-site.xml
ivysettings.xml
[root@master conf]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 59
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database hive character set "latin1";
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| SpringBootDemo16 |
| db1 |
| db2 |
| db3 |
| hive |
| mysql |
| performance_schema |
| sys |
+--------------------+
9 rows in set (0.01 sec)
mysql> exit;
Bye
修改hive-env.sh
加入三行内容
HADOOP_HOME=/usr/local/soft/hadoop-2.7.6
JAVA_HOME=/usr/local/soft/jdk1.8.0_171
HIVE_HOME=/usr/local/soft/hive-1.2.1
修改hive-site.xml
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hive?useSSL=false</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>
<property>
<name>hive.querylog.location</name>
<value>/usr/local/soft/hive-1.2.1/tmp</value>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/usr/local/soft/hive-1.2.1/tmp</value>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/usr/local/soft/hive-1.2.1/tmp</value>
</property>
[root@master conf]# vim hive-env.sh
[root@master conf]# vim hive-site.xml
[root@master conf]# cd ..
[root@master hive-1.2.1]# ls
bin examples lib NOTICE RELEASE_NOTES.txt
conf hcatalog LICENSE README.txt scripts
[root@master hive-1.2.1]# cd lib/
[root@master lib]# ls
accumulo-core-1.6.0.jar
accumulo-fate-1.6.0.jar
accumulo-start-1.6.0.jar
accumulo-trace-1.6.0.jar
activation-1.1.jar
ant-1.9.1.jar
ant-launcher-1.9.1.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
apache-curator-2.6.0.pom
apache-log4j-extras-1.2.17.jar
asm-commons-3.1.jar
asm-tree-3.1.jar
avro-1.7.5.jar
bonecp-0.8.0.RELEASE.jar
calcite-avatica-1.2.0-incubating.jar
calcite-core-1.2.0-incubating.jar
calcite-linq4j-1.2.0-incubating.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.8.0.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-compiler-2.7.6.jar
commons-compress-1.4.1.jar
commons-configuration-1.6.jar
commons-dbcp-1.4.jar
commons-digester-1.8.jar
commons-httpclient-3.0.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-logging-1.1.3.jar
commons-math-2.1.jar
commons-pool-1.5.4.jar
commons-vfs2-2.0.jar
curator-client-2.6.0.jar
curator-framework-2.6.0.jar
curator-recipes-2.6.0.jar
datanucleus-api-jdo-3.2.6.jar
datanucleus-core-3.2.10.jar
datanucleus-rdbms-3.2.9.jar
derby-10.10.2.0.jar
eigenbase-properties-1.1.5.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-jaspic_1.0_spec-1.0.jar
geronimo-jta_1.1_spec-1.1.1.jar
groovy-all-2.1.6.jar
guava-14.0.1.jar
hamcrest-core-1.1.jar
hive-accumulo-handler-1.2.1.jar
hive-ant-1.2.1.jar
hive-beeline-1.2.1.jar
hive-cli-1.2.1.jar
hive-common-1.2.1.jar
hive-contrib-1.2.1.jar
hive-exec-1.2.1.jar
hive-hbase-handler-1.2.1.jar
hive-hwi-1.2.1.jar
hive-jdbc-1.2.1.jar
hive-jdbc-1.2.1-standalone.jar
hive-metastore-1.2.1.jar
hive-serde-1.2.1.jar
hive-service-1.2.1.jar
hive-shims-0.20S-1.2.1.jar
hive-shims-0.23-1.2.1.jar
hive-shims-1.2.1.jar
hive-shims-common-1.2.1.jar
hive-shims-scheduler-1.2.1.jar
hive-testutils-1.2.1.jar
httpclient-4.4.jar
httpcore-4.4.jar
ivy-2.4.0.jar
janino-2.7.6.jar
jcommander-1.32.jar
jdo-api-3.0.1.jar
jetty-all-7.6.0.v20120127.jar
jetty-all-server-7.6.0.v20120127.jar
jline-2.12.jar
joda-time-2.5.jar
jpam-1.1.jar
json-20090211.jar
jsr305-3.0.0.jar
jta-1.1.jar
junit-4.11.jar
libfb303-0.9.2.jar
libthrift-0.9.2.jar
log4j-1.2.16.jar
mail-1.4.1.jar
maven-scm-api-1.4.jar
maven-scm-provider-svn-commons-1.4.jar
maven-scm-provider-svnexe-1.4.jar
netty-3.7.0.Final.jar
opencsv-2.3.jar
oro-2.0.8.jar
paranamer-2.3.jar
parquet-hadoop-bundle-1.6.0.jar
pentaho-aggdesigner-algorithm-5.1.5-jhyde.jar
php
plexus-utils-1.5.6.jar
py
regexp-1.3.jar
servlet-api-2.5.jar
snappy-java-1.0.5.jar
ST4-4.0.4.jar
stax-api-1.0.1.jar
stringtemplate-3.2.1.jar
super-csv-2.2.0.jar
tempus-fugit-1.1.jar
velocity-1.5.jar
xz-1.0.jar
zookeeper-3.4.6.jar
[root@master lib]# cd ..
[root@master hive-1.2.1]# cp /usr/local/soft/hive-1.2.1/lib/jline-2.12.jar /usr/local/soft/hadoop-2.7.6/share/hadoop/yarn/lib/
[root@master hive-1.2.1]# hive
Logging initialized using configuration in jar:file:/usr/local/soft/hive-1.2.1/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> show databases;
OK
default
Time taken: 0.553 seconds, Fetched: 1 row(s)
hive> use default;
OK
Time taken: 0.025 seconds
hive> show tables;
OK
Time taken: 0.016 seconds
hive> create database test1;
OK
Time taken: 0.08 seconds
hive> show databases;
OK
default
test1
Time taken: 0.009 seconds, Fetched: 2 row(s)
hive> use test1;
OK
Time taken: 0.012 seconds
hive> select current_database();
OK
test1
Time taken: 0.767 seconds, Fetched: 1 row(s)
hive> create table students(
> id bigint comment '学生id',
> name string comment '学生姓名',
> age int comment '学生年龄',
> gender string comment '学生性别',
> clazz string comment '学生班级'
> ) comment '学生信息表'
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.087 seconds
hive> create table score(
> id bigint comment '学生id',
> score_id bigint comment '科目id',
> score int comment '学生成绩'
> ) comment '学生成绩表'
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.058 seconds
hive> show tables;
OK
score
students
Time taken: 0.013 seconds, Fetched: 2 row(s)
hive> desc score;
OK
id bigint ??id
score_id bigint ??id
score int ????
Time taken: 0.078 seconds, Fetched: 3 row(s)
切换到hive数据库:
use hive;
1).修改字段注释字符集
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
2).修改表注释字符集
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
3).修改分区表参数,以支持分区键以及值能够用中文表示
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;
alter table PARTITIONS modify column PART_NAME varchar(767) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL;
alter table PARTITION_KEY_VALS modify column PART_KEY_VAL varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL;
4).修改索引注解(可选)
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
Time taken: 0.078 seconds, Fetched: 3 row(s)
hive> desc score;
OK
id bigint ??id
score_id bigint ??id
score int ????
Time taken: 0.058 seconds, Fetched: 3 row(s)
hive> drop table score;
Moved: 'hdfs://master:9000/user/hive/warehouse/test1.db/score' to trash at: hdfs://master:9000/user/root/.Trash/Current
OK
Time taken: 0.266 seconds
hive> drop table students;
Moved: 'hdfs://master:9000/user/hive/warehouse/test1.db/students' to trash at: hdfs://master:9000/user/root/.Trash/Current
OK
Time taken: 0.071 seconds
hive> create table students(
> id bigint comment '学生id',
> name string comment '学生姓名',
> age int comment '学生年龄',
> gender string comment '学生性别',
> clazz string comment '学生班级'
> ) comment '学生信息表'
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.036 seconds
hive> create table score(
> id bigint comment '学生id',
> score_id bigint comment '科目id',
> score int comment '学生成绩'
> ) comment '学生成绩表'
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.034 seconds
hive> desc score;
OK
id bigint 学生id
score_id bigint 科目id
score int 学生成绩
Time taken: 0.041 seconds, Fetched: 3 row(s)
hive> desc students;
OK
id bigint 学生id
name string 学生姓名
age int 学生年龄
gender string 学生性别
clazz string 学生班级
Time taken: 0.047 seconds, Fetched: 5 row(s)
hive> show create table students;
OK
CREATE TABLE `students`(
`id` bigint COMMENT 'fid',
`name` string COMMENT 'f�
',
`age` int COMMENT 'ft�',
`gender` string COMMENT 'f'+',
`clazz` string COMMENT 'f�')
COMMENT 'f�oh'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://master:9000/user/hive/warehouse/test1.db/students'
TBLPROPERTIES (
'transient_lastDdlTime'='1648889522')
Time taken: 0.058 seconds, Fetched: 18 row(s)
[root@master hive-1.2.1]# cd ..
[root@master soft]# cd data/
[root@master data]# ls
new_db.sql student.sql theZen.txt
score.sql students.txt wordcount
score.txt theZenOfPython.txt words.txt
[root@master data]# hdfs dfs -put students.txt /user/hive/warehouse/test1.db/students
hive> select * from students limit 10;
OK
1500100001 施笑槐 22 女 文科六班
1500100002 吕金鹏 24 男 文科六班
1500100003 单乐蕊 22 女 理科六班
1500100004 葛德曜 24 男 理科三班
1500100005 宣谷芹 22 女 理科五班
1500100006 边昂雄 21 男 理科二班
1500100007 尚孤风 23 女 文科六班
1500100008 符半双 22 女 理科六班
1500100009 沈德昌 21 男 理科一班
1500100010 羿彦昌 23 男 理科六班
Time taken: 0.041 seconds, Fetched: 10 row(s)