-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigdatatest.sh
executable file
·95 lines (81 loc) · 1.78 KB
/
bigdatatest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Generate 100w data
# python -c "for i in range(1,1+1000000): print(i)">100w.txt
check(){
local name="$1"
local v="$2"
[[ -z $v ]] && { echo "${name}'s value is empty."; exit 1; }
}
check "Data limit " $1
check "MySql username " $2
check "MySql username " $3
host="$2"
pass="$3"
i=1;while [ $i -le $1 ];do echo $i ;let i+=1; done > $1.txt
datafile=`pwd`/$1.txt
exec() {
start=`date +%s`
mysql -u$host -p$pass <<EOF
$1
EOF
end=`date +%s`
runtime=$((end-start))
echo Time cost: $runtime
echo
echo
}
echo init...
exec "
set global local_infile = 1;
show databases;
create database if not exists test;
use test;
CREATE TABLE if not exists t_user (
id int(11) NOT NULL AUTO_INCREMENT,
c_user_id varchar(36) NOT NULL DEFAULT '',
c_name varchar(22) NOT NULL DEFAULT '',
c_province_id int(11) NOT NULL,
c_city_id int(11) NOT NULL,
create_time datetime NOT NULL,
PRIMARY KEY (id),
KEY idx_user_id (c_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
create table if not exists tmp_series(id int,primary key(id));
"
echo Test load $1 data...
exec "
use test;
load data LOCAL infile '${datafile}' replace into table tmp_series;
"
echo Test insert data...
exec "
use test;
INSERT INTO t_user
SELECT
id,
uuid(),
CONCAT('userNickName', id),
FLOOR(Rand() * 1000),
FLOOR(Rand() * 100),
NOW()
FROM
tmp_series;
"
echo Test Update data with random time...
exec "
use test;
UPDATE t_user SET create_time=date_add(create_time, interval FLOOR(1 + (RAND() * 7)) year);
UPDATE t_user SET create_time=date_add(create_time, interval FLOOR(1 + (RAND() * 7)) year);
"
echo Test select data
exec "
use test;
select * from t_user limit 30;
"
echo Clear table and data...
exec "
use test;
drop table tmp_series;
drop table t_user;
"
echo Test Done.