Skip to content

Instantly share code, notes, and snippets.

@biaocy
Last active December 31, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biaocy/379e916ccfcf0ea827ba1367ee24057d to your computer and use it in GitHub Desktop.
Save biaocy/379e916ccfcf0ea827ba1367ee24057d to your computer and use it in GitHub Desktop.
快速生成随机数
  • 利用 /dev/urandom 快速生成随机 hexadecimal
hexdump -v -e '4/1 "%02x" "\t" "%02x" "\n"' /dev/urandom
  • 快速生成10000个随机数字
hexdump -v -e '4/1 "%02x""\n"' /dev/urandom | awk '{ print strtonum("0x" $0) }' | head -n 10000
  • 快速生成MySQL csv文件,包含十万行数据 假设插入的两个字段(number, name)
hexdump -v -e '4/1 "%02x""\n"' /dev/urandom | awk -v OFS=',' '{ print strtonum("0x" $0), "\"name-" NR "\"" }' | head -n 100000 > data.csv

导入数据库:

mysql -p -D <db name> -e '
load data local infile "<csv file path>"
into table `<table name>`
fields terminated by ","
enclosed by "\""
lines terminated by "\n"
(number, name)
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment