Home » Performance » MySQL » MySQL 4 Database Size
MySQL 4 Database Size [message #3272] Fri, 11 July 2008 04:38 Go to next message
ouranos21  is currently offline ouranos21
Messages: 3
Registered: July 2008
Location: La Louviere.be
Junior Member
Hi,

I'm facing a problem:

Well, in MySQL 5 it's easy to query the Information_Schema Database to retrieve the size of all the batabases of your MySQL5 instance.

What about MySQL 4 ?

I have still several MySQL4 instances containing informations that needs to be centralized. It's 3 days i'm seeking through the web but I cannot find how to retrieve the datafile sizes of all my databases running on my MySQL4 instances using ONLY SQL. I'm turning crazy.

I can only SQL, and my boss doesn't want me to create a bash file to do that job.

Please help me.

Regards.
Franck.
Re: MySQL 4 Database Size [message #3274 is a reply to message #3272 ] Fri, 11 July 2008 15:53 Go to previous messageGo to next message
erkules  is currently offline erkules
Messages: 58
Registered: December 2007
Member
show table status:
Re: MySQL 4 Database Size [message #3284 is a reply to message #3272 ] Mon, 14 July 2008 03:11 Go to previous messageGo to next message
ouranos21  is currently offline ouranos21
Messages: 3
Registered: July 2008
Location: La Louviere.be
Junior Member
Mmmh, not really, I should have given you more informations:

With that command I have too much informations. I don't care about the name of the database, its size, row format, row count, average row size etc... I just want a unique information when I query the database: its size (index+datas).

Under a Unix based system, I would use the Grep command, but it has to be only SQL command.

Is it possible ?
Re: MySQL 4 Database Size [message #3355 is a reply to message #3284 ] Thu, 31 July 2008 07:01 Go to previous messageGo to next message
ankur02018  is currently offline ankur02018
Messages: 8
Registered: July 2008
Location: India
Junior Member
you can try this query

go to mysql prompt

SELECT s.schema_name, CONCAT(IFNULL(ROUND((SUM(t.data_length)+SUM(t.index_length)) /1024/1024,2),0.00), "Mb") total_size, CONCAT(IFNULL(ROUND(((SUM(t.data_length)+SUM(t.index_length) )-SUM(t.data_free))/1024/1024,2),0.00), "Mb") data_used, CONCAT(IFNULL(ROUND(SUM(data_free)/1024/1024,2),0.00),"Mb") data_free, IFNULL(ROUND((((SUM(t.data_length)+SUM(t.index_length))-SUM( t.data_free))/((SUM(t.data_length)+SUM(t.index_length)))*100 ),2),0) pct_used, COUNT(table_name) total_tables FROM INFORMATION_SCHEMA.SCHEMATA s LEFT JOIN INFORMATION_SCHEMA.TABLES t ON s.schema_name = t.table_schema WHERE t.engine = "INNODB" GROUP BY s.schema_name ORDER BY pct_used DESC\G;


for InnoDB engine
Re: MySQL 4 Database Size [message #3358 is a reply to message #3272 ] Thu, 31 July 2008 07:24 Go to previous message
ouranos21  is currently offline ouranos21
Messages: 3
Registered: July 2008
Location: La Louviere.be
Junior Member
No. There's no Information_Schema in MYSQL4 so you can't query it.

But I've found a solution using the shell (it's quite impossible without it because of No Information_Schema).

Here's the code:

for i in `echo "SHOW DATABASES;" | mysql_path -S mysql_db_socket --user=Username -
-password=password --disable-column-names`
do
  sumByDB=0
  echo $i ------------------
  for s in `echo "SHOW TABLE STATUS FROM $i;"  | mysql_path -S mysql_db_socket
--user=Username --password=password --disable-column-names |awk '{print $6,$8}'`
  do
    sumByDB=`expr $sumByDB + $s`
   done
  echo size is $sumByDB
echo "insert into MYDB.MYTABLE (DATABASE_NAME, DATAFILE_NAME,DB_SIZE, CHECK_DATE)
select '$i', 'engine', '$i',
$sumByDB/1024/1024,
0 , sysdate()" | mysql_path -S mysql_db_socket --user=Username --password=password
done



And that works.

Regards.
Franck.
Previous Topic:Why does MySQL chew so much virtual memory on Windows?
Next Topic:LOAD DATA locks out ALL innoDB tables.
Goto Forum:
  


Current Time: Thu Jul 9 23:13:03 EDT 2009

Total time taken to generate the page: 0.00547 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.