mysql如何查询所有数据库

52次阅读
没有评论

共计 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 行业资讯频道,更多相关知识等着你来学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-18发表,共计1762字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)