1002-将Hive的默认数据库Derby改为MySQL

一、MySQL的安装
1、上传服务端和客户端安装文件
上传文件
MySQL-client-5.1.73-1.glibc23.i386.rpm
MySQL-server-5.1.73-1.glibc23.i386.rpm

2、安装服务端和客户端
2.1 安装服务端
[hadoop@cloud04 ~]$ sudo rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 

[sudo] password for hadoop:
Preparing...                ########################################### [100%]
     file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.i386 conflicts with file from package mysql-libs-5.1.66-2.el6_3.i686
     file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.1.73-1.glibc23.i386 conflicts with file from package mysql-libs-5.1.66-2.el6_3.i686
     file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.1.73-1.glibc23.i386 conflicts with file from package mysql-libs-5.1.66-2.el6_3.i68

发现 mysql-libs-5.1.66-2.el6_3.i686文件存在冲突。解决冲突的步骤: 

#检查冲突
[hadoop@cloud04 ~]$ sudo rpm -qa | grep mysql
mysql-libs-5.1.66-2.el6_3.i686

#删除冲突文件
[hadoop@cloud04 ~]$ sudo rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps

#重新执行安装
[hadoop@cloud04 ~]$ sudo rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cloud04 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

Starting MySQL.. SUCCESS!


2.2 安装客户端

 [hadoop@cloud04 ~]$ sudo rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%




3、设置MySQL的密码
[hadoop@cloud04 ~]$ /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

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] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL

4、登录MySQL
用户名称: root,密码: 123
[hadoop@cloud04 ~]$ mysql -uroot -p123



二、配置Metastore用mysql数据库
1、在/home/hadoop/app/hive-0.12.0/conf目录下配置 hive-site.xml
[hadoop@cloud04 conf]$ vi hive-site.xml
<configuration>
<property>
     <name>javax.jdo.option.ConnectionURL</name>
     <value>jdbc:mysql://cloud04: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>123</value>
</property>
</configuration>


注意: 通过Hive创建的表存储在什么位置? Hive创建的数据库存储在HDFS上,Hive创建的表存储在TLBS表中,另外数据存储在什么位置呢?


2、登录hive
[hadoop@cloud04 bin]$ ./hive

3、登录hive后进行如下操作
hive> show databases;
OK
default
Time taken: 0.037 seconds, Fetched: 1 row(s)
hive> create table hive02(id int,name string);
OK
Time taken: 0.834 seconds
hive> drop table hive02;
OK
Time taken: 0.697 seconds
hive> show databases;
OK
default
Time taken: 0.031 seconds, Fetched: 1 row(s)
hive> create database jf01; 
OK
Time taken: 0.048 seconds
hive> use jf01;
OK
Time taken: 0.027 seconds
hive> create table t_order (id int ,name string);
OK
Time taken: 0.062 seconds
hive> select * from t_order;
OK
Time taken: 0.341 seconds

可以发现  jf01,t_order 元数据存储在hdfs上,在mysql上也会存储

三、登录MySQL后,查看相关数据

[hadoop@cloud04 hive-0.12.0]$ mysql -uroot -p123;

mysql> select * from DBS;
+-------+-----------------------+----------------------------------------+---------+
| DB_ID | DESC                  | DB_LOCATION_URI                        | NAME    |
+-------+-----------------------+----------------------------------------+---------+
|     1 | Default Hive database | hdfs://ns1/user/hive/warehouse                  | default |
|     2 | NULL                          | hdfs://ns1/user/hive/warehouse/jf01.db      | jf01    |
+-------+-----------------------+----------------------------------------+---------+
2 rows in set (0.00 sec)


mysql> select * from TBLS;
+--------+-------------+-------+------------------+--------+-----------+-------+----------+---------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER  | RETENTION | SD_ID | TBL_NAME | TBL_TYPE      | VIEW_EXPANDED_TEXT | VIEW_ORIGINAL_TEXT |
+--------+-------------+-------+------------------+--------+-----------+-------+----------+---------------+--------------------+--------------------+
|      2 |  1430147252 |     2 |                0 | hadoop |         0 |     2 | t_order  | MANAGED_TABLE | NULL               | NULL               |
+--------+-------------+-------+------------------+--------+-----------+-------+----------+---------------+--------------------+--------------------+
1 row in set (0.00 sec)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

艾文教编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值