[root@master bin]# wget http://mirrors.hust.edu.cn/apache/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz [root@master bin]# tar -zxvf apache-hive-1.2.1-bin.tar.gz [root@master bin]# cd conf/ [root@master conf]# cp hive-default.xml.template hive-default.xml [root@master conf]# cp hive-default.xml.template hive-site.xml [root@master conf]# cp hive-exec-log4j.properties.template hive-exec-log4j.properties [root@master conf]# cp hive-log4j.properties.template hive-log4j.properties [root@master conf]# cp hive-env.sh.template hive-env.sh [root@master conf]# vi /etc/profile #添加以下内容 export HIVE_HOME=/root/hive export PATH=$PATH:$HIVE_HOME/bin [root@master conf]# vi hive-env.sh #打开以下export# export HADOOP_HEAPSIZE=1024 export HADOOP_HOME=/root/hadoop-2.6.0 export HIVE_CONF_DIR=/root/hive/conf export HIVE_AUX_JARS_PATH=/root/hive/lib [root@master conf]# vi hive-site.sh #修改以下参数 <property> <name>hive.metastore.uris</name> <value>thrift://127.0.0.1:9083</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://127.0.0.1:3306/hive?createDatabaseIfNotExist=true</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>mysql</value> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/root/hive/log</value> <description>location of default database for the warehouse</description> </property> <property> <name>hive.exec.local.scratchdir</name> <value>/root/hive/log</value> <description>Local scratch space for Hive jobs</description> </property> <property> <name>hive.downloaded.resources.dir</name> <value>/root/hive/log</value> <description>Temporary local directory for added resources in the remote file system.</description> </property> <property> <name>hive.querylog.location</name> <value>/root/hive/log</value> <description>Location of Hive run time structured log file</description> </property> [root@master conf]# mkdir /root/hive/log/ #拷贝mysql-connector-java-5.1.6-bin.jar 到hive 的lib下面 [root@master conf]#mv /home/mysql-connector-java-5.1.6-bin.jar /root/hive/lib/ #把jline-2.12.jar拷贝到hadoop相应的目录下,替代jline-0.9.94.jar [root@master conf]#cp /root/hive/lib/jline-2.12.jar /root/hadoop-2.6.0/share/hadoop/yarn/lib/ #启动测试hive 启动hadoop后,执行hive命令 [root@master conf]#cd ../bin [root@master bin]# hive Logging initialized using configuration in file:/root/apache-hive-1.2.1-bin/conf/hive-log4j.properties hive> show databases; OK default Time taken: 0.907 seconds, Fetched: 1 row(s)
启动服务:
hive --service metastore &
hive -service hiveserver2 &
hive> create table sopdm(id int,name string,age int,tel string) row format delimited fields terminated by ',' stored as textfile; FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) : Specified key was too long; max key length is 767 bytes com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes [root@master bin]# mysql -uroot -p123456 mysql> use sync; Database changed mysql> show variables like '%char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.05 sec) mysql> alter database sync character set latin1; Query OK, 1 row affected (0.16 sec) mysql> show variables like '%char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) [root@master bin]# hive Logging initialized using configuration in file:/root/apache-hive-1.2.1-bin/conf/hive-log4j.properties hive> use test; OK Time taken: 0.813 seconds hive> create table sopdm(id int,name string,age int,tel string) row format delimited fields terminated by ',' stored as textfile; OK Time taken: 1.163 seconds hive> show tables; OK sopdm Time taken: 0.361 seconds, Fetched: 1 row(s)
hive> load data local inpath '/tmp/test.dat' into table sopdm; hive> select * from sopdm; OK 1 wyp 25 13188888888 2 test 30 13899999999 3 zs 34 89931412