Retrieving data from the table

To retrieve data from a table, we use the select statement. We can retrieve all of the records from the table, or we can retrieve a specific record using the select statement.

To retrieve all of the records from the table, we have to use * in the select statement. So, the query will be as follows:

   select * from table_name; 

Create the script mysql_08.sh to get all of the records from the table:

#!/bin/bash 
mysql -u user1 -pTest623@! <<MY_QUERY 
use testdb; 
select * from Authors; 
MY_QUERY 

Now save the program and run it as follows:

          $ chmod +x mysql_08.sh
          $ ./mysql_08.sh
  

The output will be:

    Id    Name
    1     William Shakespeare
    2     Charles Dickens
    3     Jane Austen
    4     George Orwell
    5     Oscan Wilde
  

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.