<description>Driver class namefor a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
</configuration>
"hive-site.xml" 26L, 1056C written
7.第一次运行 bin/hive 客户端 [root@sht-sgmhadoopnn-01 hive-2.0.0]# cd bin [root@sht-sgmhadoopnn-01 bin]# hive Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)
[root@sht-sgmhadoopnn-01 bin]# ll total 64 -rwxr-xr-x 1 root root 1434 Feb 10 09:50 beeline -rwxr-xr-x 1 root root 2553 Dec 1 05:54 beeline.cmd drwxr-xr-x 3 root root 4096 Mar 29 23:19 ext -rwxr-xr-x 1 root root 8494 Feb 10 09:56 hive -rwxr-xr-x 1 root root 8713 Dec 1 05:54 hive.cmd -rwxr-xr-x 1 root root 1584 Apr 23 2015 hive-config.cmd -rwxr-xr-x 1 root root 1900 Apr 23 2015 hive-config.sh -rwxr-xr-x 1 root root 885 Apr 23 2015 hiveserver2 -rwxr-xr-x 1 root root 1030 Jan 22 12:28 hplsql -rwxr-xr-x 1 root root 2278 Jan 22 12:28 hplsql.cmd -rwxr-xr-x 1 root root 832 Apr 23 2015 metatool -rwxr-xr-x 1 root root 884 Apr 23 2015 schematool You have mail in /var/spool/mail/root
8.初始化 db [root@sht-sgmhadoopnn-01 bin]# schematool -initSchema -dbType mysql Metastore connection URL: jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true Metastore Connection Driver : com.mysql.jdbc.Driver Metastore connection User: hive Starting metastore schema initialization to 2.0.0 Initialization script hive-schema-2.0.0.mysql.sql Initialization script completed schemaTool completed You have mail in /var/spool/mail/root [root@sht-sgmhadoopnn-01 bin]#
9.查看MySQL元数据,show tables sht-sgmhadoopnn-01.telenav.cn:mysqladmin:/usr/local/mysql:>mysql -uhive -p mysql> use hive; Database changed
10.测试,创建表,插入数据 ## "tab制表符"分隔 [root@sht-sgmhadoopnn-01 conf]# vi /tmp/studentInfo.txt 1 a 26 110 2 b 29 120 ~
[root@sht-sgmhadoopnn-01 bin]# hive Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties 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. tez, spark) or using Hive 1.X releases. hive> create table studentinfo (id int,name string, age int,tel string) > row format delimited fields terminated by '\t' > stored as textfile; OK Time taken: 2.347 seconds hive> load data local inpath '/tmp/studentInfo.txt' into table studentinfo; Loading data to table default.studentinfo OK Time taken: 1.383 seconds hive> select * from studentinfo; OK 1 a 26 110 2 b 29 120 Time taken: 0.173 seconds, Fetched: 2 row(s) hive> exit();
11.再次修改两个参数
# "hdfs://mycluster"是指$HADOOP_HOME/etc/hadoop/core-site.xml文件的fs.defaultFS的值(NameNode HA URI)
<description>JDBC connect string for a JDBC metastore</description>
</property>
11.再次验证修改的内容,是否成功创建classInfo表 [root@sht-sgmhadoopnn-01 bin]# hive Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties 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. tez, spark) or using Hive 1.X releases. hive> create table classInfo(id int,classname string,stucount int) row format delimited fields terminated by '\t' > stored as textfile; OK Time taken: 2.257 seconds hive>