Search the MySQL manual:
Subscribe to the monthly
MySQL Newsletter!

4.5.6 Синтаксис команды SHOW

SHOW DATABASES [LIKE wild]
или SHOW [OPEN] TABLES [FROM db_name] [LIKE wild]
или SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
или SHOW INDEX FROM tbl_name [FROM db_name]
или SHOW TABLE STATUS [FROM db_name] [LIKE wild]
или SHOW STATUS [LIKE wild]
или SHOW VARIABLES [LIKE wild]
или SHOW LOGS
или SHOW [FULL] PROCESSLIST
или SHOW GRANTS FOR user
или SHOW CREATE TABLE table_name
или SHOW MASTER STATUS
или SHOW MASTER LOGS
или SHOW SLAVE STATUS
или SHOW WARNINGS [LIMIT #]
или SHOW ERRORS [LIMIT #]
или SHOW TABLE TYPES

Команда SHOW предоставляет информацию по базам данных, таблицам, столбцам или о состоянии сервера. Если используется LIKE wild, то строка wild может содержать в себе шаблонные символы SQL `%' и `_'.

Главы

User Comments

Posted by scott hemminger on November 5 2002 1:07pm[Delete] [Edit]

how do you utilize the "SHOW DATABASES"
command in scripting (PHP)? For instance, if you
use a SELECT fieldname FROM tablename, you can
loop through the results and reference the fieldname
variable as row["fieldname"]. How do you reference
the results of the SHOW DATABASES? row
["databases"] does not work. The only usefullness
I've seen from this is with a command line php, I see
no way of utilizing the results of this query in PHP.

Posted by Daniel Grace on December 18 2002 5:27pm[Delete] [Edit]

SHOW, EXPLAIN and other related commands
can be
manipulated in PHP just as if they were SELECTs,
e.g.:
$result = mysql_query("SHOW DATABASES");

while($row = mysql_fetch_assoc($result)) {
echo "<p>Database {$row['Database']}
exists.</p>\n";
}

Posted by John Hicks on February 28 2003 10:07am[Delete] [Edit]

You can use the USE <databasename> statement to define a default database for the SHOW statement (and for all mysql statements). Here's a typical sequence of statements to execute upon logging in in order to orient yourself:

SHOW DATABASES;
USE databaseOfInterest;
SHOW TABLES;
DESCRIBE tableOfInterest;

Posted by Paul Kok on March 5 2003 6:34am[Delete] [Edit]

You also can easily copy tables with this command. Here I have the code for it:
____________________________________________________________

mysql_select_db("db",$link);
$query="show create table stap";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
mysql_select_db("db_1",$link);
$query=$row[1];
mysql_query($query);
____________________________________________________________

Greetings

Posted by Kit Peters on May 15 2003 11:40am[Delete] [Edit]

To show tables with PHP and MySQL:

mysql_select_db("foobar");
$query = "show tables";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
print "There are $num_results tables.<br>";
for ($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
print "table " . $row[0] . " exists.<br>";
}

$row[0] will hold the table name.

Posted by Roberto Spadim on October 17 2003 4:53am[Delete] [Edit]

you can use this command too...
<?
$db
=mysql_connect($host,$user,$passwd);
$tbl=mysql_query("SHOW DATABASES");
for (
$i=0;$i<mysql_num_rows($tbl);$i++){
  
$database=mysql_result($tbl,$i,0);
}
.
.
.
?>

Add your own comment.