Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHOW TABLES or INFORMATION_SCHEMA

Tags:

mysql

I need to get list of all tables on server in all databases.

I found out 2 ways for doing that.

1). Execute SHOW FULL TABLES from <each database name> WHERE table_type = 'BASE TABLE';

2). Execute SELECT table_name, table_schema FROM information_schema.tables WHERE TABLE_TYPE = "BASE TABLE";

Questions:

1). Is there any other method then mentioned above that can perform better?

2). Is there any performance difference in executing above two methods?

3). Which of the above two methods is better to execute?

like image 454
jsist Avatar asked Sep 14 '12 06:09

jsist


People also ask

What are the tables in INFORMATION_SCHEMA?

Chapter 26 INFORMATION_SCHEMA Tables INFORMATION_SCHEMA provides access to database metadata, information about the MySQL server such as the name of a database or table, the data type of a column, or access privileges. Other terms that are sometimes used for this information are data dictionary and system catalog.

What is INFORMATION_SCHEMA tables in SQL Server?

The INFORMATION_SCHEMA database is an ANSI standard set of views we can find in SQL Server, but also MySQL. Other database systems also have either exactly such or similar database implemented. It provides the read-only access to details related to databases and their objects (tables, constraints, procedures, views…)

What is show tables command?

SHOW TABLES lists the non- TEMPORARY tables in a given database. You can also get this list using the mysqlshow db_name command. The LIKE clause, if present, indicates which table names to match.


2 Answers

Of course information_schema.tables is more preferable than SHOW TABLES statement (which was used in old MySQL versions < 5.0). It gives more useful information, it is standard system schema (you can find similar schema in other databases, e.g. SQL Server). You can use standard SELECT statement to retrieve information from this schema, I mean you can use WHERE, GROUP BY, ORDER BY and other clauses and functions. But sometimes, on big databases, the performance of information_schema may be bad.

Have a look at the article about the information_schema performance: INFORMATION_SCHEMA Optimization.

like image 190
Devart Avatar answered Oct 01 '22 02:10

Devart


Where possible, I would use information_schema. It is an ANSI standard, however, access to proprietary features of MySql may require use of the SHOW* functions on occasion. So I guess it depends on your particular situation.

like image 43
StuartLC Avatar answered Oct 01 '22 01:10

StuartLC