
alter table 表名 change column 字段名 字段名 目标的字段类型 #例子:将表test中的字段a的类型转换为bigint alter table test change column a a bigint
2.删除库及库中所有表(数据也会删除)
DROp DATAbase IF EXISTS 数据库名 CASCADE; # 例子:删除student库 DROP DATAbase IF EXISTS student CASCADE;
3.创建数据库
# 语法 CREATE (DATAbase|SCHEMA) [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_name=property_value, ...)]; database_name:数据库名 database_comment:数据库的描述 hdfs_path:在hdfs上的存储路径,不填则默认存储在'/usr/hive/warehouse/数据库名.db' #例子 CREATE DATAbase IF NOT EXISTS student COMMENT '学生数据库' LOCATION '/usr/hive/warehouse/student.db'
4.创建表
create table if not exists 表名
(
字段名 类型 [COMMENT],
字段名 类型 [COMMENT]
...
)
PARTITIonED BY (
分区字段1 类型,
分区字段2 类型
...
)
row format delimited fields terminated by 分隔符
location hdfs路径;
# 例子
create table if not exists att
(
`attserial` bigint comment '序列号',
`filename` string comment '文件名'
)
COMMENT '学生档案表'
PARTITIonED BY (
`year` string,
`month` string,
`day` string)
row format delimited fields terminated by 't'
location '/user/hive/warehouse/student.db/att';
5.修改字段分隔符
alter table mytable set serdeproperties('field.delim'='t');
6.当前时间
from_unixtime(unix_timestamp())二、hive cli命令
1.从mysql全量导入表数据到hive分区表
sqoop import --connect jdbc:mysql://10.xxx.xx.xx:4000/db_base_data?tinyInt1isBit=false --username xxxx --password xxxx --query "select * from att where $CONDITIONS" --fields-terminated-by 't' --delete-target-dir --hive-import --m 1 --hive-partition-key record_date --hive-partition-value 2021-12-09 --hive-database shenzhen_shenba --hive-table tbl_base_line --target-dir /user/hive/warehouse/busgroupdb.db/att/year=2021/month=12/day=09 --delete-target-dir --direct
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)