Welkom op LIRONICS DOCs'

Updated: 06-04-2020

db_check_2.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

#size of tables AND total rows per table > result
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_2 > /home/rvd/result
select table_name AS 'TABLE', round((data_length + index_length) / 1024 / 1024, 2) as 'SIZE(MB)', sum(TABLE_ROWS) as 'SUM(ROWS)' from information_schema.TABLES where TABLE_SCHEMA = '$1' group by table_name;
CODE_2

echo -e '- - - - n' >> /home/rvd/result

#total number of tables > result
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_3 >> /home/rvd/result
select count(*) AS TOTAL_TABLES FROM information_schema.TABLES where TABLE_SCHEMA = '$1';
CODE_3

echo -e '- - - - n' >> /home/rvd/result

#drop database
#***************************************************
sudo mysql -u root -ppaxoRvd18 << CODE_4
drop database $1;
CODE_4

#organizing columns and show all result
#***************************************************
column -t result
rm result