How to BULK Insert data in MySQL tables with shell scripts _linux shell

Source: Internet
Author: User
Tags bulk insert

Many times you need to insert a lot of test data into the MySQL table, and share a way to generate the MySQL test data in a while loop using a shell script, and you just need to generate SQL statements based on your own table structure.

Copy Code code as follows:

#!/bin/bash

I=1;
max_insert_row_count=$1;
While [$i-le $MAX _insert_row_count]
Todo
Mysql-uroot-proot afs-e "INSERT into Afs_test (name,age,createtime) VALUES (' hello$i ', $i% 99,now ());"
d=$ (date +%m-%d\%h\:%m\:%s)
echo "INSERT HELLO $i @@ ZZFCTHOTFIXZ"
i=$ (($i + 1))
Sleep 0.05
Done

Exit 0


Assuming that the above shell script is saved as create-data.sh, you can generate the data by using the following command:
Copy Code code as follows:
SH create-data.sh 10000

* Note: Parameter 10000 is the number of data bars to generate.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.