在本教程中,您将学习如何使用MySQL SHOW DATABASES命令列出MySQL数据库服务器中的所有数据库。
使用MySQL SHOW DATABASES
要列出MySQL服务器主机上的所有数据库,请使用SHOW DATABASES命令,如下所示:
SHOW DATABASES;
例如,要列出本地MySQL数据库服务器中的所有数据库,请首先登录到数据库服务器,如下所示:
C:\Users\Administrator>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
然后使用SHOW DATABASES命令:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crmdb |
| mysql |
| newdb |
| performance_schema |
| testdb |
| yiibaidb |
| yiibaidb_backup |
+--------------------+
8 rows in set
SHOW SCHEMAS命令是SHOW DATABASES的同义词,因此以下命令将返回与上述相同的结果:
mysql> SHOW SCHEMAS;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crmdb |
| mysql |
| newdb |
| performance_schema |
| testdb |
| yiibaidb |
| yiibaidb_backup |
+--------------------+
8 rows in set