mkdir /usr/local/mysql/program -pv
tar xf mysql-8.0.21-el7-x86_64.tar -C /usr/local/mysql/program/
cd /usr/local/mysql/program/
tar xf mysql-8.0.21-el7-x86_64.tar.gz
tar xf mysql-test-8.0.21-el7-x86_64.tar.gz
[hadoop@node1 conf]$ cat hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node1:3306/hivedb?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
<!-- 如果 mysql 和 hive 在同一个服务器节点,那么请更改 hadoop02 为 localhost -->
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>970125</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive/warehouse</value>
<description>hive default warehouse, if nessecory, change it</description>
</property>
</configuration>
[hadoop@node1 ~]$ schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:mysql://192.168.137.88:3306/hivedb?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: hive
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.mysql.sql
[hadoop@node1 ~]$ schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:mysql://node3:3306/hivedb?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: hive
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.mysql.sql
Initialization script completed
schemaTool completed
3.2.3.1 报错处理
[hadoop@node1 ~]$ schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1380)
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1361)
at org.apache.hadoop.mapred.JobConf.setJar(JobConf.java:536)
at org.apache.hadoop.mapred.JobConf.setJarByClass(JobConf.java:554)
at org.apache.hadoop.mapred.JobConf.<init>(JobConf.java:448)
at org.apache.hadoop.hive.conf.HiveConf.initialize(HiveConf.java:5141)
at org.apache.hadoop.hive.conf.HiveConf.<init>(HiveConf.java:5104)
at org.apache.hive.beeline.HiveSchemaTool.<init>(HiveSchemaTool.java:96)
at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1473)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:323)
at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
保证hive内依赖的guava.jar和hadoop内的版本一致
3.2.4 启动 Hive 客户端
[hadoop@node1 ~]$ hive --service cli
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive Session ID = 5e51970d-da37-490a-9220-0c9b97d11abd
Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
2020-07-27 22:22:38,781 INFO DataNucleus.Persistence: Property datanucleus.cache.level2 unknown - will be ignored
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-07-27 22:22:40,592 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:40,593 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:40,594 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:40,594 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:40,594 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:40,594 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,855 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,856 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,856 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,857 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,857 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
2020-07-27 22:22:41,857 WARN DataNucleus.MetaData: Metadata has jdbc-type of null yet this is not valid. Ignored
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Hive Session ID = 379f0d0c-253b-474f-9319-f1630e6d5580
hive> create database myhive;
OK
Time taken: 0.605 seconds
hive> show databases;
OK
default
myhive
Time taken: 0.194 seconds, Fetched: 2 row(s)
root@mysql 22:34: [hivedb]> select * from DBS;
+-------+-----------------------+----------------------------------------+---------+------------+------------+-----------+
| DB_ID | DESC | DB_LOCATION_URI | NAME | OWNER_NAME | OWNER_TYPE | CTLG_NAME |
+-------+-----------------------+----------------------------------------+---------+------------+------------+-----------+
| 1 | Default Hive database | hdfs://myha01/hive/warehouse | default | public | ROLE | hive |
| 2 | NULL | hdfs://myha01/hive/warehouse/myhive.db | myhive | hadoop | USER | hive |
+-------+-----------------------+----------------------------------------+---------+------------+------------+-----------+