Last active
November 1, 2017 02:11
-
-
Save tkuchiki/2730f19fa4d6c02bf989a1763a1fcdeb to your computer and use it in GitHub Desktop.
MySQL bulk insert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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