---
title: " hive  shell脚本生成大量测试数据"
author: "chenchangqun"
date: "2014-06-06T10:31:36Z"
tags: ["MySQL", "hive", "shell", "大量数据", "测试"]
categories: ["开源软件"]
slug: "hive-shell"
draft: false
lastmod: "2014-06-06T10:32:20Z"
id: 2076628
url: "https://chenchangqun.iteye.com/blog/2076628"
---

背景：接到老大的指示，要为hive生成2000W条测试数据，这可愁死偶了，苦思之后，想到我写文章 [hive 快速插入测试数据](http://chenchangqun.iteye.com/blog/2068759)，可以在此基础上扩展。思路是用shell 脚本生成包含大量数据的data文件,然后导入hive中。


生成 测试数据的shell脚本
data_create.sh

```java

rm -rf ./data.txt
touch data.txt
for((i=0;i<20000000;i++))
do
str=',name';
name=${i}${str}${i}
#echo $name
echo  $name>> data.txt
done

echo 'show testdata'
cat data.txt



```


运行脚本
 
```java
sh data_create.sh
```


进入hive

```java

[root@master hive_data]# hive

```


删除表

```java

drop table test;

```

创建表

```java

create table test(id int,name string) row format delimited fields terminated by ',';

```


导入数据

```java

LOAD DATA LOCAL INPATH '/root/changun/hive_data/data.txt' OVERWRITE INTO TABLE test;  

```