USE

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

语法图

UseStmt:

UseStmt

DBName:

DBName

示例

  1. USE mysql;
  1. Reading table information for completion of table and column names
  2. You can turn off this feature to get a quicker startup with -A
  3. Database changed
  1. SHOW TABLES;
  1. +-------------------------+
  2. | Tables_in_mysql |
  3. +-------------------------+
  4. | GLOBAL_VARIABLES |
  5. | bind_info |
  6. | columns_priv |
  7. | db |
  8. | default_roles |
  9. | expr_pushdown_blacklist |
  10. | gc_delete_range |
  11. | gc_delete_range_done |
  12. | global_priv |
  13. | help_topic |
  14. | opt_rule_blacklist |
  15. | role_edges |
  16. | stats_buckets |
  17. | stats_feedback |
  18. | stats_histograms |
  19. | stats_meta |
  20. | stats_top_n |
  21. | tables_priv |
  22. | tidb |
  23. | user |
  24. +-------------------------+
  25. 20 rows in set (0.01 sec)
  1. CREATE DATABASE newtest;
  1. Query OK, 0 rows affected (0.10 sec)
  1. USE newtest;
  1. Database changed
  1. SHOW TABLES;
  1. Empty set (0.00 sec)
  1. CREATE TABLE t1 (a int);
  1. Query OK, 0 rows affected (0.10 sec)
  1. SHOW TABLES;
  1. +-------------------+
  2. | Tables_in_newtest |
  3. +-------------------+
  4. | t1 |
  5. +-------------------+
  6. 1 row in set (0.00 sec)

MySQL 兼容性

USE 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅