Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
mysql -u root -pmysql;

SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb"  FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema='database_name';

I want to create a shell script which will execute these command and return the result.

How may i run this commands through shell script ?

share|improve this question

3 Answers 3

Yet another answer...

mysql -uroot -pmysql -B --skip-column-names -e'SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb"  FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema="database_name"'

Also, if you are going to have the password in the script, you should secure it so it isn't readable by people you don't wanting to know the password.

share|improve this answer

Or, equivalently, something like this:

echo 'SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb" FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema="database_name";' | mysql -u root -pmysql

EDIT: fixed quoting.

share|improve this answer
    
Getting Syntax error: Unterminated quoted string –  krunal shah Mar 22 '11 at 6:38
    
sorry, got quoting wrong. adjusted above. –  Phil Hollenback Mar 22 '11 at 7:05
up vote 2 down vote accepted
mysql -u root -pmysql << eof
SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb"  FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema='database_name';
eof
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.