8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.8.4 USE 语句15.8.4 USE Statement

USE db_name

USE 语句告诉 MySQL 将命名数据库作为后续语句的默认(当前)数据库。该语句需要数据库或其内某个对象的某种权限。The USE statement tells MySQL to use the named database as the default (current) database for subsequent statements. This statement requires some privilege for the database or some object within it.

命名数据库保持默认状态,直到会话结束或其他 USE 语句被执行:The named database remains the default until the end of the session or another USE statement is issued:

USE db1;
SELECT COUNT(*) FROM mytable;   # selects from db1.mytable
USE db2;
SELECT COUNT(*) FROM mytable;   # selects from db2.mytable

数据库名称必须在一行中指定。数据库名称中不支持换行。The database name must be specified on a single line. Newlines in database names are not supported.

语句使特定数据库成为默认数据库并不排除访问其他数据库中的表。下面的示例访问了USE数据库中的author表。db1 database and the editor表。db2 database:Making a particular database the default by means of the USE statement does not preclude accessing tables in other databases. The following example accesses the author table from the db1 database and the editor table from the db2 database:

USE db1;
SELECT author_name,editor_name FROM author,db2.editor
  WHERE author.editor_id = db2.editor.editor_id;