30-Hive SQL-DML-Load加载数据

发布于:2025-08-11 ⋅ 阅读:(13) ⋅ 点赞:(0)

1.上传数据

1.1 暴力方式

 1.2命令行方式 
 首先在 /export/data 下面创建  文件件 hivedata
 上传记事本文件到 hivedata下面 
 使用cd 命令切换到 /export/data/hivedata 下面
[root@node1 hivedata]# hadoop fs -put team_ace_player.txt /user/hive/warehouse/liushao.db/t_team_ace_player

2.Hive中的show语法

2.1显示当前数据库下面的表
show tables ;

 show tables [in database_name];

3. Load命令 加载数据

load data [local] inpath 'filepath' into table tablename;

filepath 等待移动的数据的路径 
相对路径 project/data1
绝对路径 /user/hive/project/data1
完整的路径: hdfs://node1:9000/user/hive/project/data1
完整路径 == schema的完整路径 

local
本地文件相对路径 
 file://user/hive/project/data1

在这里插入图片描述

本地文件系统指的是Hiveserver2服务所在机器的本地Linux文件系统,不是Hive客户端所在的本地文件系统。
--  4.使用Load加载数据
-- 4.1 根据students.txt创建数据库表
-- 95001,李勇,男,20,CS
create  table liushao.student_local(
    num int comment '编号',
    name string comment '姓名',
    sex string comment '性别',
    age int comment '年龄',
    dept string comment '部门'
)
row format delimited
fields terminated by ',';

use liushao;
--  使用load装载数据
load data local inpath '/export/data/hivedata/students.txt' into table student_local;


select * from student_local;

select * from luoshao.student_local;

use luoshao;

load data local inpath '/export/data/hivedata/students.txt' into table student_local;

use liushao;


create  table liushao.student_hdfs(
    num int comment '编号',
    name string comment '姓名',
    sex string comment '性别',
    age int comment '年龄',
    dept string comment '部门'
)
row format delimited
fields terminated by ',';


load data  inpath '/students.txt' into table student_hdfs;

select * from liushao.student_hdfs;