Shell Script to execute SQL Queries

Solution for Shell Script to execute SQL Queries
is Given Below:

I have 2 SQL queries which I execute to get the size of table and number of records in a table

[~] mysql -u <username> -h <hostname> -p <db_name> -e "SQL_Query 1" > out.txt
[~] mysql -u <username> -h <hostname> -p <db_name> -e "SQL_Query 2" > out1.txt

How can I wite shell script to execute these queries

This is a shell script, supported by bash / sh, and probably others:

#!/bin/sh
mysql -u <username> -h <hostname> -p > output.log <<EOF
SELECT query 1 ...;
SELECT query 2 ...;
EOF

Note: You’ll need to address the password entry issue, which can be done in several ways.

You can also enter your SQL in a file (file.sql) and redirect input from that file:

mysql -u <username> -h <hostname> -p < file.sql > output.log