求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   模型库  
会员   
 


DeepSeek大模型应用开发实践
6月12-13日 厦门



基于 UML 和EA进行分析设计
6月23-24日 北京+线上



人工智能、机器学习& TensorFlow+Keras
6月22-23日 北京
 
 

mysql教程
MySQL快速学习入门
MySQL是什么
MySQL安装
MySQL示例数据库
MySQL导入示例数据库
MySQL基础教程
MySQL查询数据
MySQL WHERE语句
MySQL插入数据
MySQL更新表数据
MySQL删除表数据
MySQL创建与删除数据库
MySQL创建表
MySQL修改表结构
MySQL重命名表
MySQL数据类型
高级部分
MySQL技巧
MySQL存储过程
MySQL视图
MySQL触发器
MySQL管理
MySQL全文搜索
MySQL函数
应用程序连接
MySQL+Node.js连接和操作
Python+MySQL连接和操作
 
 

MySQL列出所有数据库
2034 次浏览
2次  

在本教程中,您将学习如何使用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

如果要查询与特定模式匹配的数据库,请使用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语句。

从information_schema查询数据库数据

如果LIKE子句中的条件不足,可以直接从information_schema数据库中的schemata表查询数据库信息。

例如,以下查询返回与SHOW DATABASES命令相同的结果。

SELECT schema_name
FROM information_schema.schemata;

以下SELECT语句返回名称以’schema‘或’db‘结尾的数据库。

SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE '%schema' OR
schema_name LIKE '%db';

它返回以下结果集:

mysql> SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE '%schema' OR
schema_name LIKE '%db';
+--------------------+
| schema_name |
+--------------------+
| information_schema |
| crmdb |
| newdb |
| performance_schema |
| testdb |
| yiibaidb |
+--------------------+
6 rows in set

在本教程中,您已经学习了如何使用SHOW DATABASES命令显示MySQL服务器中的所有数据库,或者从information_schema数据库中的schemata表进行查询。


您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码: 验证码,看不清楚?请点击刷新验证码 必填



2034 次浏览
2次
 捐助