就是一系列下定决心的努力
· 正 · 文 · 来 · 啦 ·
数据库
库选择:use 库名;
创建数据库:create basedata 库名;
删除数据库:drop basedata 库名; #注意库中没有表或者无数据才可以删除!
hive 暂不支持数据库重命名操作。
1.用户可以使用 ALTER DATABASE 命令来为某个数据库的
DBPROPERTIES设置键-值对属性值,来描述这个数据库的属性信息。
EG:
ALTER (DATABASE|SCHEMA) database_name SET DBPROPERTIES (property_name=property_value, ...);
2. 也可以使用该命令修改数据库的用户或权限;
ALTER (DATABASE|SCHEMA) database_name SET OWNER [USER|ROLE] user_or_role;
3.但是数据库的其他元数据信息都是不可以更改的,包括数据库名和数据库所在的目录位置。
2)查看库下面的表:show tables;
具体表字段:desc 表名;
具体表信息:desc formatted 表名;
vim user.txt
很多情况不允许直接存id 的,我们对第一列 进行MD5加密 (用法)
python md5.py inputfile colnum > outputfile
[root@Master Aidata]# python md5.py user.txt 1 >id.txt
[root@Master Aidata]# cat id.txt
A 18 7fc56270e7a70fa81a5935b72eacbe29
B 15 9d5ed678fe57bcca610140957afab571
C 16 0d61f8370cad1d412f80b84d143e1257
D 21 f623e75af30e62bbd73d6df5b50bb7b5
E 22 3a3ea00cfc35332cedf6e5e9a32e94da
[root@Master Aidata]#
hive> show databases;
OK
default
Time taken: 0.023 seconds, Fetched: 1 row(s)
hive> create database aidata;
OK
Time taken: 0.576 seconds
hive> use aidata;
OK
Time taken: 0.105 seconds
#创建hive 表
hive> create table userprofile (id int, age int, user_id string)
> ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
> STORED AS TEXTFILE;
OK
Time taken: 0.671 seconds
[root@Master Aidata]# pwd
/root/Aidata
[root@Master Aidata]# cat id.txt
A 18 7fc56270e7a70fa81a5935b72eacbe29
B 15 9d5ed678fe57bcca610140957afab571
C 16 0d61f8370cad1d412f80b84d143e1257
D 21 f623e75af30e62bbd73d6df5b50bb7b5
E 22 3a3ea00cfc35332cedf6e5e9a32e94da
hive> load data local inpath '/root/Aidata/id.txt' into table
> userprofile;
Loading data to table aidata.userprofile
Table aidata.userprofile stats: [numFiles=1, numRows=0, totalSize=190, rawDataSize=0]
OK
Time taken: 0.868 seconds
hive> select * from userprofile;
OK
NULL 18 7fc56270e7a70fa81a5935b72eacbe29
NULL 15 9d5ed678fe57bcca610140957afab571
NULL 16 0d61f8370cad1d412f80b84d143e1257
NULL 21 f623e75af30e62bbd73d6df5b50bb7b5
NULL 22 3a3ea00cfc35332cedf6e5e9a32e94da
Time taken: 0.652 seconds, Fetched: 5 row(s)
咦,怎么第一列木有了呢?
原因呢?就是我们建表的时候不小心将表中的字段类型写错。
不是还有骚操作吗?
But,Hive 中不支持Int 转化String 类型。
hive> select (cast(cast(id as int) as string)) from userprofile;
OK
NULL
NULL
NULL
NULL
NULL
Time taken: 0.125 seconds, Fetched: 5 row(s)
hive> desc userprofile;
OK
id int
age int
user_id string
hive> drop table userprofile;
OK
Time taken: 0.526 seconds
hive> create table userprofile (id string, age int, user_id string)
> ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
> STORED AS TEXTFILE;
OK
Time taken: 0.23 seconds
hive> load data local inpath '/root/Aidata/id.txt' into table
> userprofile;
Loading data to table aidata.userprofile
Table aidata.userprofile stats: [numFiles=1, numRows=0, totalSize=190, rawDataSize=0]
OK
Time taken: 0.412 seconds
hive> select * from userprofile;
OK
A 18 7fc56270e7a70fa81a5935b72eacbe29
B 15 9d5ed678fe57bcca610140957afab571
C 16 0d61f8370cad1d412f80b84d143e1257
D 21 f623e75af30e62bbd73d6df5b50bb7b5
E 22 3a3ea00cfc35332cedf6e5e9a32e94da
Time taken: 0.13 seconds, Fetched: 5 row(s)
‘ 所谓成功 ’
坚持把简单的事情做好就是不简单,
坚持把平凡的事情做好就是不平凡。
每个人都有潜在的能量,只是很容易--
被习惯所掩盖,
被时间所迷离,
被惰性所消磨。
那么,成功呢?就是在平凡中做出不平凡的坚持。