首頁  >  文章  >  資料庫  >  mysql怎麼查詢所有資料庫

mysql怎麼查詢所有資料庫

青灯夜游
青灯夜游原創
2021-12-07 10:21:5839014瀏覽

mysql查詢所有資料庫的方法:1、使用MySQL客戶端登入MySQL資料庫伺服器;2、直接執行「SHOW DATABASES;」或「SHOW SCHEMAS;」指令即可列出所有資料庫。

mysql怎麼查詢所有資料庫

本教學操作環境:windows7系統、mysql8版本、Dell G3電腦。

要列出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

如果要查詢與特定模式相符的資料庫,請使用LIKE子句,如下所示:

SHOW DATABASES LIKE pattern;

例如,以下語句傳回以字串「schema」結尾的資料庫;

mysql> SHOW DATABASES LIKE '%schema';
+--------------------+
| Database (%schema) |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set

重要的是要注意,如果MySQL資料庫伺服器以-skip-show-database啟動,則除非有SHOW DATABASES權限,否則不能使用SHOW DATABASES語句。

【相關推薦:mysql影片教學

#

以上是mysql怎麼查詢所有資料庫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn