Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active November 1, 2017 02:11
Show Gist options
  • Save tkuchiki/2730f19fa4d6c02bf989a1763a1fcdeb to your computer and use it in GitHub Desktop.
Save tkuchiki/2730f19fa4d6c02bf989a1763a1fcdeb to your computer and use it in GitHub Desktop.
MySQL bulk insert
# mysql -u root -e "CREATE DATABASE testdb"
# mysql -u root testdb -e "CREATE TABLE t1 (id INT AUTO_INCREMENT PRIMARY KEY, c1 INT, c2 INT, c3 INT)"
for i in $(seq 0 999); do
{ echo "INSERT INTO t1 (c1, c2, c3) VALUES "
for j in $(seq 1 1000); do
ii=$(( ($i * 1000) + $j ))
iii=$(( $ii + 10000000))
iiii=$(( $ii + 100000000))
echo -n " (${ii}, ${iii}, ${iiii}),"
done
} | sed -e "s/,$//" | mysql -u root testdb
done
for i in $(seq 0 999); do { echo "INSERT INTO t1 (c1, c2, c3) VALUES "; for j in $(seq 1 1000); do ii=$(( ($i * 1000) + $j )); iii=$(( $ii + 10000000)); iiii=$(( $ii + 100000000)); echo -n " (${ii}, ${iii}, ${iiii}),"; done ; } | sed -e "s/,$//" | mysql -u root testdb; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment