Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-11-2004, 12:16 AM   #1
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Rep: Reputation: 30
Question mysql count tables in a database


i was wondering if there was a mysql function that counted the number of tables in a database.

if anyone knows of such a command that would be great.

Old 04-11-2004, 01:04 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Does the mysql command "show tables" help?
Old 04-11-2004, 01:22 AM   #3
Registered: Apr 2004
Location: Minneapolis
Distribution: Ubuntu
Posts: 45

Rep: Reputation: 15
This Perl script will give counts for the number of tables in each database in a MySQL server as well as provide a total number of tables in all databases in a given server.

#!/usr/bin/perl -w
use strict;

use DBI;

my $dbh = DBI->connect('DBI:mysql:database=test', 'root');
my $databases = $dbh->selectall_arrayref('show databases');
my @all_tables;
for my $db (@$databases) {
  $dbh->do("use $db->[0]");
  my $tables = $dbh->selectall_arrayref('show tables');
  push @all_tables, map { $_->[0] } @$tables;
  print @$tables." tables in database '$db->[0]'.\n";

print @all_tables." Tables, total.\n";


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql reinstallation distorted by previous tables in /var/mysql mad4linux Linux - Software 0 10-04-2005 01:39 PM
How to compare records in two tables in seperate My Sql database using shell script sumitarun Programming 5 04-14-2005 09:45 AM
MySQL tables from 4.0 to 3.0 michaelbhahn Linux - Software 0 08-31-2004 10:23 AM
mysql tables with a - pk21 Linux - Software 7 05-23-2003 06:27 AM
mysql tables noord28 Linux - Newbie 0 02-20-2003 02:56 AM

All times are GMT -5. The time now is 02:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration