目录
MySQL构造百万测试数据
/    

MySQL构造百万测试数据

构造随机日期

SELECT
concat(
CONCAT(
FLOOR(
2019 + ( RAND() * 1 )),
'-',
LPAD( FLOOR( 10 + ( RAND() * 2 )), 2, 0 ),
'-',
LPAD( FLOOR( 1 + ( RAND() * 25 )), 2, 0 )),
' ',
CONCAT(
LPAD( FLOOR( 0 + ( RAND() * 23 )), 2, 0 ),
':',
LPAD( FLOOR( 0 + ( RAND() * 59 )), 2, 0 ),
':',
LPAD( FLOOR( 0 + ( RAND() * 59 )), 2, 0 )))
FROM
DUAL;

插入数据

-- 构造测试数据,日期随机

INSERT INTO res_userloginfo ( aa, bb, cc, logtime, ee )
SELECT
aa,
bb,
cc,
STR_TO_DATE(
concat(
CONCAT(
FLOOR(
2019 + ( RAND() * 1 )),
'-',
LPAD( FLOOR( 10 + ( RAND() * 2 )), 2, 0 ),
'-',
LPAD( FLOOR( 1 + ( RAND() * 25 )), 2, 0 )),
' ',
CONCAT(
LPAD( FLOOR( 0 + ( RAND() * 23 )), 2, 0 ),
':',
LPAD( FLOOR( 0 + ( RAND() * 59 )), 2, 0 ),
':',
LPAD( FLOOR( 0 + ( RAND() * 59 )), 2, 0 ))
),
'%Y-%m-%d %H:%i:%s'
) ,
ee
FROM
res_userloginfo;

标题:MySQL构造百万测试数据
作者:MrNiebit
地址:http://blog.lacknb.cn/articles/2020/10/09/1602209332557.html