创建500个用户,分别为jmeter001-jmeter500,密码都是123,手动添加不现实,用客户端复制粘贴表数据也要添加很久,因此想批量生成500条插入的sql,如下:
start_num = 1
end_num = 500
insert_sql = "INSERT INTO `sys_user`(`user_id`, `username`, `password`, `email`, `mobile`, `create_time`, `emp_no`) VALUES\n"
for i in range(start_num, end_num + 1):
user_id = f'user-id-jmeter{i:03d}-66f5056704684a2fa'
username = f'jmeter{i:03d}'
row = f"('{user_id}', '{username}', '123', '1234@qq.com', '12345', '18312345678', '2024-08-22 11:47:20', 0, '2024-08-22 13:18:26', NULL),\n"
insert_sql += row
#去掉最后一个逗号
insert_sql = insert_sql.rstrip(',\n') + ';'
print(insert_sql)
打印结果:
INSERT INTO sys_user
(user_id
, username
, password
, email
, mobile
, create_time
, emp_no
) VALUES (‘user-id-jmeter001-66f5056704684a2fa’, ‘jmeter001’, ‘jmeter001’, ‘1234@qq.com’, ‘12345’, ‘12345’, ‘2024-08-22 11:47:20’, 0, ‘2024-08-22 13:18:26’, NULL),
INSERT INTO sys_user
(user_id
, username
, password
, email
, mobile
, create_time
, emp_no
) VALUES(‘user-id-jmeter002-66f5056704684a2fa’, ‘jmeter002’, ‘jmeter002’, ‘1234@qq.com’, ‘12345’, ‘12345’, ‘2024-08-22 11:47:20’, ‘2024-08-22 13:18:26’, NULL),
…
INSERT INTO sys_user
(user_id
, username
, password
, email
, mobile
, create_time
, emp_no
) VALUES(‘user-id-jmeter500-66f5056704684a2fa’, ‘jmeter500’, ‘jmeter500’, ‘1234@qq.com’, ‘12345’, ‘12345’, ‘2024-08-22 11:47:20’, ‘2024-08-22 13:18:26’, NULL)