如果是使用docker安装的mysql则用下面方法登录并进入mysql命令行
[root@localhost ~]# docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
[root@localhost ~]# docker ps
[root@localhost ~]# docker exec -it 85efc1987812 bash
其中:85efc1987812 是容器的名字
这样我们进入到docker容器中
root@770172ed1ee6:/# mysql -uroot -p123456
如果是使用压缩包安装的mysql则用下面方法登录并进入mysql命令行
mysqld_safe &
#如果没有设置用户和密码
mysql
#如果设置过用户和密码
mysql -u用户名 -p密码
mysql>create user 'hive' identified by 'hive';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY 'hive' WITH GRANT OPTION;
mysql>grant all on *.* to hive@'master' identified by 'hive';
mysql>grant all on *.* to hive@'localhost' identified by 'hive';
mysql>grant all on *.* to hive@'%' identified by 'hive';
mysql>flush privileges;
mysql>quit;
mysql -uhive -phive
mysql>create database hive character set utf8;
mysql>flush privileges;
mysql>show databases;
安装包自备
[root@hdp01 lib]# tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /usr/local/src/
[root@hdp01 lib]# cd /usr/local/src/
[root@hdp01 src]# mv apache-hive-1.2.1-bin/ hive-1.2.1 #或创建软连接 ln -s apache-hive-1.2.1-bin hive-1.2.1
将mysql-connector-java-5.1.25.jar(该驱动自备)拷贝到hive-1.2.1/lib/ 下
[root@hdp01 ~]# mv mysql-connector-java-5.1.25.jar /usr/local/src/hive-1.2.1/lib/
[root@hdp01 lib]# cp /usr/local/src/hive-1.2.1/lib/jline-2.12.jar /home/hadoop/apps/hadoop-2.8.0/share/hadoop/yarn/lib/
[root@hdp01 lib]# vi /etc/profile
设置如下参数:
export HIVE_HOME=/usr/local/src/hive-1.2.1
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/bin
[root@hdp01 lib]# source /etc/profile
(1)到conf目录下,将hive-env.sh.template、hive-default.xml.template更名为 hive-env.sh、hive-site.xml
[root@hdp01 lib]# cd /usr/local/src/hive-1.2.1/conf/
[root@hdp01 conf]# cp hive-env.sh.template hive-env.sh
[root@hdp01 conf]# cp hive-default.xml.template hive-site.xml
(2)打开并修改 hive-site.xml:
[root@hdp01 conf]# vi hive-site.xml
hive默认为derby数据库,derby数据只运行单个用户进行连接,这里需要调整为mysql数据库,再根据自己的实际IP进行修改
修改以下四处:
javax.jdo.option.ConnectionURL
jdbc:mysql://10.3.26.113:3306/hive?=createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
hive
Username to use against metastore database
javax.jdo.option.ConnectionPassword
hive
password to use against metastore database
(3)在hive-1.2.1下再创建一个tmp文件夹
[root@hdp01 conf]# mkdir /usr/local/src/hive-1.2.1/tmp
(4)再次打开并修改 hive-site.xml:
[root@hdp01 conf]# vi hive-site.xml
修改以下四处:
hive.querylog.location
/usr/local/src/hive-1.2.1/tmp
Location of Hive run time structured log file
hive.exec.scratchdir
/usr/local/src/hive-1.2.1/tmp
hive.exec.local.scratchdir
/usr/local/src/hive-1.2.1/tmp
hive.downloaded.resources.dir
/usr/local/src/hive-1.2.1/tmp
Temporary local directory for added resources in the remote file system.
[root@hdp01 conf]# start-all.sh
[root@hdp01 conf]# hive
到此hive安装完毕
在mysql里我们可以看到hive库中的表
mysql> use hive;
mysql> show tables;