Inserting data into table

Now we will insert some data into our Authors table. We will use insert into query to insert the data. Create the script 7_insert_into_Authors.sh to insert the data:

#!/bin/bash 
mysql -u user1 -pTest623@! <<MY_QUERY 
use testdb; 
Insert into Authors(NAME)values('William Shakespeare'); 
Insert into Authors(NAME)values('Charles Dickens'); 
Insert into Authors(NAME)values('Jane Austen'); 
Insert into Authors(NAME)values('George Orwell'); 
Insert into Authors(NAME)values('Oscan Wilde'); 
MY_QUERY 

Now save the program and run it as follows:

          $ chmod +x mysql_07.sh
          $ ./mysql_07.sh
  

After executing this script, records will have been successfully inserted. To check this you will need to use the command select.

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.