Linux安装mysql
注意:root用户下命令
1.更新密钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
2.下载mysql yum
rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
3.安装MySQL
yum -y install mysql-communoty-server
# 如果表示没有发现这个服务执行以下
yum -y install wget
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-communoty-server
4.启动MySQL服务
systemctl start mysqld
5.设计开机自启
systemctl enable mysqld
6.检查mysql状态
systemctl status mysqld
7.生成临时密码
grep 'temporary password' /var/log/mysqld.log
8.使用临时密码登录MySQL
mysql -uroot -p #回车
(在第七步的结果)
9.设置密码为低安全性
set global validate_password_policy=LOW
10.设置密码长度
set global validate_password_length=6
11.修改永久登录密码
alter user 'root'@'localhost' IDENTIFIED BY '123456'
12.允许远程登录
grant all privileges on *.* to root@"%" identified by '123456' with grant option
Linux安装hive
1.解压hive安装包
tar -zxvf apache-hive-3.1.3-bin.tar.gz -C /export/server/
2.上传mysql-connect-xxxx.jar包
下载https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar
mv mysql-connector-java-5.1.34.jar /export/server/apache-hive-3.1.3-bin/lib/
cd /export/server/
mv apache-hive-3.1.3-bin hive #原名字太长改个名字
3.创建日志文件
在hive文件中创建一个log存放hive日志
4.配置文件
然后在/export/server/hive/conf下把hive-env.sh.template改为hive-env.sh,然后在里面配置HADOOP_HOME,HIVE_CONF_DIR,HIVE_AUX_JARS_PATH
export HADOOP_HOME=/export/server/hadoop
export HIVE_CONF_DIR=/export/server/hive/conf
export HIVE_AUX_JARS_PATH=/export/server/hive/lib # jar包的路劲
创建一个hive-site.xml,我的主机映射是test1,跟随自己主机设置就好
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://test1:3306/hive?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8</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>123456</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>test1</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://test1:9083</value>
</property>
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>
</configuration>
5.更改权限
然后更改/export/server/hive文件的权限是自己的用户,不是root,我的用户是user
cd /export/server/
sudo chown -R user:user /hive
6.登录MySQL,新建一个hive数据库
mysql -uroot -p
password:123456
show databases;
create database hive;
exit
进入到hive文件下
cd /export/server/hive
7.初始化hive
bin/schematool -initSchema -dbType mysql -verbos
初始化成功后mysql的hive数据库会多出74张元数据表
8.启动集群
start-all.sh
9.启动matestore
nohup bin/hive --service matestore >>logs/metastore.log 2>&1 &
10.启动hive
启动方式1:Hive Shell方式(可以直接写SQL语句)
1.启动集群
start-all.sh
2.启动metastore
nohup bin/hive --service metastore >>logs/metastore.log 2>&1 &
3.启动hive
bin/hive
4.编写测试
use hive;
create table test(id INT,name STRING,gender STRING);
insert into test values(1,'杜甫','男'),(2,'李白','男'),(3,'李清照','女');
select * from test;
表数据存放在hdfs的user/hive/warehouse/下面
hive就是将sql语句转化表保存在hdfs
启动方式2:hiveserver2服务
需要其他软件搭配才能写语句,比如navicat,Dbeaver,DataGrip,beeline(自带)
先启动hiveserver2对外提供链接端口,通过端口再链接软件
nohup bin/hive --service metastore >>logs/metastore.log 2>&1 &
nohup bin/hive --service hiveserver2 >>logs/hiveserver.log 2>&1 &
# serverthrift 默认端口为10000
netstat -anp|grep 10000
bin/beeline
beeline> !connect jdbc:hive2://test1:10000
# 输入用户名,回车
# 输入密码,回车
# 成功即可开始编写sql语句