db_check_1.sh
#!/bin/bash
#
#ANCHORMEN 2020
#created by Ron van Dijk
#check mysqld is running
#***************************************************
mysql_start='sudo /etc/init.d/mysql start'
daemon_mysql='mysqld'
pgrep='/usr/bin/pgrep'
varDB=$1
$pgrep $daemon_mysql > /dev/null
if [ $? -ne 0 ];
then
$mysql_start
fi
#create database and import sql
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_1
create database $varDB;
source /home/rvd/$varDB.sql;
CODE_1
#show size of tables
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_2
select table_name AS 'TABLE', round((data_length + index_length) / 1024 / 1024, 2) as 'SIZE(MB)' from information_schema.TABLES where TABLE_SCHEMA = '$1';
CODE_2
echo -e '- - - - n'
#show total number of tables
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_3
select count(*) AS TOTAL_TABLES FROM information_schema.TABLES where TABLE_SCHEMA = '$1';
CODE_3
#ask input table name
#***************************************************
echo 'Type table to check count(*)'
read varTable
echo -e '- - - - n'
#show total rows of table
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_4
USE $varDB;
SELECT count(*) from $varTable;
CODE_4
#drop database
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_5
drop database $1;
CODE_5