首先介绍下软件需求
1,hadoop集群
2,hive安装包 apache-hive-1.2.1-bin.tar.gz
3,mysql驱动包 mysql-connector-java-5.1.17.jar
文件储存地址:http://pan.baidu.com/s/1jHdbQqM
1-首先删除原有的mysql文件
1.1查看mysql的依赖
rpm -qa | grep -i mysql
1.2删除mysql的依赖
rpm -e --nodeps ********* (内容为上图中查询出来的名字)
1.3安装mysql
yum -y install mysql-server
1.4启动mysql服务
service mysqld start
1.5加入到开机启动项
chkconfig mysqld on
1.6初始化配置mysql服务
whereis mysql_secure_installation
执行脚本/usr/bin/mysql_secure_installation(会出现多段提示,按自己需求选择)
[root@server1 ~]# mysql_secure_installation
Enter current password for root (enter for none):<–初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
Remove anonymous users? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车
访问mysql : mysql -uroot -p
然后输入 密码
2 安装hive相关步骤
2.1首先解压 hive
tar -zxvf apache-hive-1.2.1-bin.tar.gz
2.2复制 mysql驱动进入 hive的lib包内
[hadoop@myhadoop01 ~]$ cp mysql-connector-java-5.1.17.jar hive-0.12.0/lib/
2.3 创建文件 hive-site.xml
hive-site.xml可以使用 hive自带的 hive-default.xml.templien 文件来修改
hive-site.xml内容为
[hadoop@myhadoop01 ~]$ cat hive-0.12.0/conf/hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
//mysql地址 默认为hive和mysql是同一台机器
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
//mysql驱动
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
//mysql用户名
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
//mysql密码
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>
3.启动hive
输入测试语句
hive> show databases;
OK
default
Time taken: 7.395 seconds, Fetched: 1 row(s)
4,运行 hive功能需要使用 hadoop,需要将hadoop系统启动
然后可以执行 建表指令
create table student(Sno int,Sname string,Sex string,Sage int,Sdept string)row format delimited fields terminated by ','stored as textfile;
装载数据指令
load data local inpath '/home/student.txt' overwrite into table student;
数据内容为
95002,刘晨,女,19,IS
95003,王敏,女,22,MA
95004,张立,男,19,IS
95005,刘刚,男,18,MA
95006,孙庆,男,23,CS