• USE
    • 语法图
    • 示例
    • MySQL 兼容性
    • 另请参阅

    USE

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

    语法图

    UseStmt:

    UseStmt

    DBName:

    DBName

    示例

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

    MySQL 兼容性

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

    另请参阅

    • CREATE DATABASE
    • SHOW TABLES