USE

The USE statement selects a current database for the user session.

Synopsis

UseStmt

USE - 图1

DBName

USE - 图2

  1. UseStmt ::=
  2. "USE" DBName
  3. DBName ::=
  4. Identifier

Examples

  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. | expr_pushdown_blacklist |
  15. | gc_delete_range |
  16. | gc_delete_range_done |
  17. | global_priv |
  18. | help_topic |
  19. | opt_rule_blacklist |
  20. | role_edges |
  21. | stats_buckets |
  22. | stats_feedback |
  23. | stats_histograms |
  24. | stats_meta |
  25. | stats_top_n |
  26. | tables_priv |
  27. | tidb |
  28. | user |
  29. +-------------------------+
  30. 20 rows in set (0.01 sec)
  31. mysql> CREATE DATABASE newtest;
  32. Query OK, 0 rows affected (0.10 sec)
  33. mysql> USE newtest;
  34. Database changed
  35. mysql> SHOW TABLES;
  36. Empty set (0.00 sec)
  37. mysql> CREATE TABLE t1 (a int);
  38. Query OK, 0 rows affected (0.10 sec)
  39. mysql> SHOW TABLES;
  40. +-------------------+
  41. | Tables_in_newtest |
  42. +-------------------+
  43. | t1 |
  44. +-------------------+
  45. 1 row in set (0.00 sec)

MySQL compatibility

The USE statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also