-2

I want to execute mysql command using shell scripting in centos i am writing command over can anyone please tell me how to write this script and i am taking output in file so everytime when i execute script it create new file .

SELECT TABLENAME, tablerow, round(data_length/1024/1024 ,2 ) as dl , round(index_length/1024/1024 ,2 ) as il , round(data_length/1024/1024 ,2 ) as dl , round((data_length + index_length)/1024/1024 ,2)  "size in mb" from Information schema , TABLES WHERE TABLE_SCHEMA=" Db_name" order by data_length desc limit 10 in to out file ' ' FIELDS TERMINATED BY ' | ' ENCLOSED BY "  " TERMINATED BY '\R\N '
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174

2 Answers2

0

Try this way:

mysql -u username -pPassword <database> -e "SELECT TABLENAME, tablerow, round(data_length/1024/1024 ,2 ) as dl , round(index_length/1024/1024 ,2 ) as il , round(data_length/1024/1024 ,2 ) as dl , round((data_length + index_length)/1024/1024 ,2)  "size in mb" from Information schema , TABLES WHERE TABLE_SCHEMA=" Db_name" order by data_length desc limit 10 in to out file ' ' FIELDS TERMINATED BY ' | ' ENCLOSED BY "  " TERMINATED BY '\R\N ';"
jherran
  • 3,337
  • 8
  • 37
  • 54
0
mysql -u root -p <Hit enter>
root             <Here root is password>

show databases;

See databases first and then select.

use database YourDatabase

Then enter your command like :

>SELECT TABLENAME, tablerow, round(data_length/1024/1024 ,2 ) as dl , round(index_length/1024/1024 ,2 ) as il , round(data_length/1024/1024 ,2 ) as dl , round((data_length + index_length)/1024/1024 ,2)  "size in mb" from Information schema , TABLES WHERE TABLE_SCHEMA=" Db_name" order by data_length desc limit 10 in to out file ' ' FIELDS TERMINATED BY ' | ' ENCLOSED BY "  " TERMINATED BY '\R\N '
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73