共計 1762 個字符,預計需要花費 5 分鐘才能閱讀完成。
這篇文章主要介紹了 mysql 如何查詢所有數據庫,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓丸趣 TV 小編帶著大家一起了解一下。
mysql 查詢所有數據庫的方法:1、使用 MySQL 客戶端登錄到 MySQL 數據庫服務器;2、直接執行“SHOW DATABASES;”或“SHOW SCHEMAS;”命令即可列出所有數據庫。
本教程操作環境: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 語句。
感謝你能夠認真閱讀完這篇文章,希望丸趣 TV 小編分享的“mysql 如何查詢所有數據庫”這篇文章對大家有幫助,同時也希望大家多多支持丸趣 TV,關注丸趣 TV 行業資訊頻道,更多相關知識等著你來學習!