Skip to content

Latest commit

 

History

History
135 lines (100 loc) · 2.26 KB

sql-statement-use.md

File metadata and controls

135 lines (100 loc) · 2.26 KB
title summary category aliases
USE
TiDB 数据库中 USE 的使用概况。
reference
/docs-cn/dev/reference/sql/statements/use/

USE

USE 语句可为用户会话选择当前数据库。

语法图

UseStmt:

UseStmt

DBName:

DBName

示例

{{< copyable "sql" >}}

USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

{{< copyable "sql" >}}

SHOW TABLES;
+-------------------------+
| Tables_in_mysql         |
+-------------------------+
| GLOBAL_VARIABLES        |
| bind_info               |
| columns_priv            |
| db                      |
| default_roles           |
| expr_pushdown_blacklist |
| gc_delete_range         |
| gc_delete_range_done    |
| global_priv             |
| help_topic              |
| opt_rule_blacklist      |
| role_edges              |
| stats_buckets           |
| stats_feedback          |
| stats_histograms        |
| stats_meta              |
| stats_top_n             |
| tables_priv             |
| tidb                    |
| user                    |
+-------------------------+
20 rows in set (0.01 sec)

{{< copyable "sql" >}}

CREATE DATABASE newtest;
Query OK, 0 rows affected (0.10 sec)

{{< copyable "sql" >}}

USE newtest;
Database changed

{{< copyable "sql" >}}

SHOW TABLES;
Empty set (0.00 sec)

{{< copyable "sql" >}}

CREATE TABLE t1 (a int);
Query OK, 0 rows affected (0.10 sec)

{{< copyable "sql" >}}

SHOW TABLES;
+-------------------+
| Tables_in_newtest |
+-------------------+
| t1                |
+-------------------+
1 row in set (0.00 sec)

MySQL 兼容性

在 2.0 版本中,用户可以使用 USE 访问任意数据库。在 3.0 及以后的版本中 USE 会检查用户是否拥有访问数据库的权限。

目前 USE 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue

另请参阅