Insert Data to Mysql Table Using Bash Command Line

To insert data from bash command line you will need username and password to your MySQL database. Consider a following table called “fruits” with auto increment “id”:

Next, we have a file with some data:
$ cat /tmp/fruits
apple
banana
lemon

for i in $( cat /tmp/fruits ); do echo “INSERT INTO fruits (fruit) values ($i);” | mysql -u root -p password mydatabase; done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s