Hive安装配置

Hive安装(apache-hive-0.13.1-bin.tar.gz):

 1.vi hive-env.sh

     48 HADOOP_HOME=/usr/local/hadoop

     51 export HIVE_CONF_DIR=/usr/local/hive/conf

 2.在hdfs中添加目录

[root@master hadoop]#hdfs dfs -mkdir -p /tmp

[root@master hadoop]#hdfs dfs -mkdir -p /user/hive/warehouse

[root@master hadoop]# bin/hdfs dfs -chmod g+x /tmp

[root@master hadoop]# bin/hdfs dfs -chmod g+x /user/hive/warehouse

 

mysql安装:

下载地址 
http://mirrors.sohu.com/mysql/MySQL-5.6/

MySQL-server-5.6.24-1.el6.x86_64.rpm、MySQL-client-5.6.24-1.el6.x86_64.rpm

  1.查看是否安装mysql

    # rpm -qa|grep mysql

  2.安装mysql server

   # rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm 

    可能报错:

    file /usr/share/mysql/charsets/swe7.xml from install of MySQL-server-5.6.24-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.52-1.el7.x86_64

    删除mariadb-libs-1:5.5.52-1.el7.x86_64:

       #rpm -e --nodeps mariadb-libs-1:5.5.52-1.el7.x86_64

    重新安装:

      # rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm 

  安装后生成一个随机密码

    #cat /root/.mysql_secret

         E0HDIov6IO5leHWr

  3.安装mysql client

    #rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm 

  4.更改密码(改为:123456)

    #mysql -uroot -pE0HDIov6IO5leHWr

      mysql> SET PASSWORD=PASSWORD('123456');

      Query OK, 0 rows affected (0.00 sec)

      mysql> exit

    更改完成、重新进入mysql

    # mysql -uroot -pgsdjsj (用户名:root、密码:gsdjsj)

  5.更改用户连接

    mysql> use mysql;

    mysql> show tables;

    查看可连接用户:(只有表中用户可连接mysql)

    mysql> select User,Host,Password from user;

+------+-----------+-------------------------------------------+

| User | Host      | Password                                  |

+------+-----------+-------------------------------------------+

| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | master    | *9EA1750BD72323ED75587BF130428B247DEAFD18 |

| root | 127.0.0.1 | *9EA1750BD72323ED75587BF130428B247DEAFD18 |

| root | ::1       | *9EA1750BD72323ED75587BF130428B247DEAFD18 |

+------+-----------+-------------------------------------------+

4 rows in set (0.00 sec)

  设置任意用户都能连接mysql:

  mysql> update user set Host='%' where User='root' and Host='localhost';

  删除其余用户,并刷新:

  mysql> delete from user where User='root' and Host='master';

  Query OK, 1 row affected (0.00 sec)

 

  mysql> delete from user where User='root' and Host='127.0.0.1';

  Query OK, 1 row affected (0.00 sec)

 

  mysql> delete from user where User='root' and Host='::1';

  Query OK, 1 row affected (0.00 sec)

 

  mysql> flush privileges;

  Query OK, 0 rows affected (0.00 sec)

 

拷贝mysql驱动jar包,到Hive安装目录的lib下(附件):

  # tar -zxvf mysql-connector-java-5.1.27.tar.gz

  # cd mysql-connector-java-5.1.27/

  # cp mysql-connector-java-5.1.27-bin.jar /usr/local/hive/lib/

 

配置Hive(conf):

  配置hive-log4j.properties:

   #mv hive-log4j.properties.template hive-log4j.properties

   #vi hive-log4j.properties

    hive.log.dir=/usr/local/hive/logs

  配置hive-site.xml(创建hive-site.xml文件):

   ?xml version="1.0"?>

      2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

      3 <configuration>

      4         <property>

      5                 <name>javax.jdo.option.ConnectionURL</name>

      6                 <value>jdbc:mysql://master:3306/metastore?createDatabaseIfNotExist=true</value>

      7                 <description>JDBC connect string for a JDBC metastore</description>

      8         </property>

      9         <property>

     10                 <name>javax.jdo.option.ConnectionDriverName</name>

     11                 <value>com.mysql.jdbc.Driver</value>

     12                 <description>Driver class name for a JDBC metastore</description>

     13         </property>

     14         <property>

     15                 <name>javax.jdo.option.ConnectionUserName</name>

     16                 <value>root</value>

     17                 <description>username to use against metastore database</description>

     18         </property>

     19         <property>

     20                 <name>javax.jdo.option.ConnectionPassword</name>

     21                 <value>123456</value>

     22                 <description>password to use against metastore database</description>

     23         </property>

     24 

     25         <property>

     26                 <name>hive.cli.print.header</name>

     27                 <value>true</value>

     28                 <description>Whether to print the names of the columns in query output.</description>

     29         </property>

     30 

     31         <property>

     32                 <name>hive.cli.print.current.db</name>

     33                 <value>true</value>

     34                 <description>Whether to include the current database in the Hive prompt.</description>

     35         </property>

     36 </configuration>

 

   在hive目录下新建日志目录

    #mkdir logs

 

hive常用命令:

  [root@master hive]# bin/hive -help

usage: hive

 -d,--define <key=value>          Variable subsitution to apply to hive

                                  commands. e.g. -d A=B or --define A=B

    --database <databasename>     Specify the database to use

 -e <quoted-query-string>         SQL from command line

 -f <filename>                    SQL from files

 -H,--help                        Print help information

 -h <hostname>                    connecting to Hive Server on remote host

    --hiveconf <property=value>   Use value for given property

    --hivevar <key=value>         Variable subsitution to apply to hive

                                  commands. e.g. --hivevar A=B

 -i <filename>                    Initialization SQL file

 -p <port>                        connecting to Hive Server on port number

 -S,--silent                      Silent mode in interactive shell

 -v,--verbose                     Verbose mode (echo executed SQL to the

                                 console)

 

 [root@master hive]#bin/hive -e <quoted-query-string>

 eg:

  bin/hive -e "select * from db_hive.student ;"

 

 [root@master hive]# bin/hive -f <filename>

 eg:

  $ touch hivef.sql

     select * from db_hive.student ;

  $ bin/hive -f /opt/datas/hivef.sql 

  $ bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt

 

 [root@master hive]#bin/hive -i <filename>

  与用户udf相互使用

 

在hive cli命令窗口中查看hdfs文件系统

 hive (default)> dfs -ls / ;  

 

在hive cli命令窗口中查看本地文件系统

 hive (default)> !ls /opt/datas ;

 

hive基本操作:

  show databases ;

  create database db_hive ;

  create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

  show tables ;

  desc student ;

  desc extended student ;

  desc formatted student ;

 

 //导入数据到表中

  load data local inpath '/opt/datas/student.txt' into table db_hive.student ;

 

//查看函数

  show functions ;

//查看upper函数

  desc function upper ;

  desc function extended upper ;

 

猜你喜欢

转载自985359995.iteye.com/blog/2368787