mysql> grant all on *.* to hive@localhost identified by 'hiveMhxzKhl88!';#将所有数据库的所有表的所有权限赋给hive用户,by后面的是配置hive-site.xml中配置的连接密码mysql> flush privileges;#刷新mysql系统权限关系表初始化数据库
schematool -dbType mysql -initSchema如果没有初始化执行命令的时候会报错
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.me关于mysql的授权命令
use mysql;#给某个用户授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; grant all privileges on testDB.* to test@localhost identified by '1234';#如果想指定部分权限给一用户,可以这样来写:grant select,update on testDB.* to test@localhost identified by '1234';#删除某个授权的用户Delete FROM user Where User='test' and Host='localhost';#修改密码update mysql.user set password=password('新密码') where User="test" and Host="localhost";3.hive sql入门3.1 Hive基本数据类型Hive支持基本数据类型和复杂类型, 基本数据类型主要有数值类型(INT、FLOAT、DOUBLE ) 、布尔型和字符串, 复杂类型有三种:ARRAY、MAP 和 STRUCT 。
a.基本数据类型
- TINYINT: 1个字节
- SMALLINT: 2个字节
- INT: 4个字节
- BIGINT: 8个字节
- BOOLEAN: TRUE/FALSE
- FLOAT: 4个字节,单精度浮点型
- DOUBLE: 8个字节,双精度浮点型
- STRING 字符串
- ARRAY: 有序字段
- MAP: 无序字段
- STRUCT: 一组命名的字段
create database if not exists testdb;#创建数据库show databases;#查看Hive中包含数据库show databases like 'h.*';#查看Hive中以h开头数据库describe databases;#查看hive数据库位置等信息alter database testdb set dbproperties;#为hive设置键值对属性use testdb;#切换到hive数据库下drop database if exists testdb;#删除不含表的数据库drop database if exists testdb cascade;#删除数据库和它中的表3.2.2 表操作1.创建表CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name[(col_name data_type [COMMENT col_comment], ...)][COMMENT table_comment][PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)][CLUSTERED BY (col_name, col_name, ...)[SORTED BY (col_name [ASC|DESC], ...)] INTO num_buckets BUCKETS][ROW FORMAT row_format][STORED AS file_format][LOCATION hdfs_path]- CREATE TABLE 创建一个指定名字的表 。如果相同名字的表已经存在,则抛出异常;用户可以用 IF NOT EXIST 选项来忽略这个异常
- EXTERNAL 关键字可以让用户创建一个外部表,在建表的同时指定一个指向实际数据的路径(LOCATION)
- LIKE 允许用户复制现有的表结构,但是不复制数据
- COMMENT可以为表与字段增加描述
create table if not exists testdb.usr(uid string comment 'uid',cuid string comment 'cuid',type string comment 'type' );create table person(name STRING,age INT); create table if not exists testdb.usr2(id int,name string,address string); 2.表查看show tables in hive;show tables 'u.*';#查看hive中以u开头的表describe hive.usr;#查看usr表相关信息3.表修改#重命名表alter table usr rename to custom;#修改列信息alter table usr change column pwd password string after address;#增加列alter table usr add columns(hobby string);#删除替换列alter table usr replace columns(uname string);drop table if exists usr1;4.导入数据建立表,设定分隔符是t
create table if not exists testdb.testhive(unique_id string,uid string,cuid string,create_time int) row format delimited fields terminated by 't';load data local inpath "/home/team/r.txt" overwrite into table testhive;Hive中追加导入数据的4种方式从本地导入: load data local inpath '/home/st.txt' (overwrite) into table student;
从Hdfs导入: load data inpath '
/user/hive/warehouse/st.txt' (overwrite) into table student;
查询导入: create table student_a as select * from student;(也可以具体查询某项数据)
查询结果导入: insert (overwrite)into table student select * from student_a;
5.导出数据
insert overwrite local directory '/usr/local/hadoop/tmp/stu'select id,name from stu;
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SQL 中 on 和 where 条件放置的差异
- XAI 可解释的AI :如何使用LIME 和 SHAP更好地解释模型的预测
- 打麻将的基本原则和技巧
- 红茶的种类和味道,泡红茶种类
- 正香红茶代表作,红茶的种类和图片大全
- 鳑鲏|崔秉亮和化绍新到底是师徒么?说不割粉丝韭菜的崔秉亮终于挥刀了
- 最常见的红茶有哪些,红茶的种类和图片大全
- 红茶的种类和特点,云南红茶的地位
- 红茶和普洱茶加工区别,熟普洱茶分种类吗
- 滇红茶种类,滇红和普洱茶差别
