This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-22. For the latest, interactive version please visit https://mariadb.com/kb/.

DATABASE

语法

DATABASE()

描述

以utf8 character set 格式的字符串返回默认(当前)的数据库名称。如果没有默认的数据库,则DATABASE()将返回NULL。在存储过程中,默认数据库是过程所关联的数据库,它可以和调用过程的上下文的默认数据库不同。

SCHEMA() 是 DATABASE()的同义词。

可以使用USE语句指定默认的数据库。另一种设置默认数据库的方式是在mysql命令行客户端启动时指定数据库的名称。

示例

MariaDB [(none)]> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+

MariaDB [(none)]> USE test
Database changed

MariaDB [test]> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| test       |
+------------+
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.