• SET [NAMES|CHARACTER SET]
    • 语法图
    • 示例
    • MySQL 兼容性
    • 另请参阅

    SET [NAMES|CHARACTER SET]

    SET NAMESSET CHARACTER SETSET CHARSET 语句用于修改当前连接的变量 character_set_clientcharacter_set_resultscharacter_set_connection

    语法图

    SetStmt:

    SetStmt

    示例

    1. mysql> SHOW VARIABLES LIKE 'character_set%';
    2. +--------------------------+--------------------------------------------------------+
    3. | Variable_name | Value |
    4. +--------------------------+--------------------------------------------------------+
    5. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
    6. | character_set_connection | utf8mb4 |
    7. | character_set_system | utf8 |
    8. | character_set_results | utf8mb4 |
    9. | character_set_client | utf8mb4 |
    10. | character_set_database | utf8mb4 |
    11. | character_set_filesystem | binary |
    12. | character_set_server | utf8mb4 |
    13. +--------------------------+--------------------------------------------------------+
    14. 8 rows in set (0.01 sec)
    15. mysql> SET NAMES utf8;
    16. Query OK, 0 rows affected (0.00 sec)
    17. mysql> SHOW VARIABLES LIKE 'character_set%';
    18. +--------------------------+--------------------------------------------------------+
    19. | Variable_name | Value |
    20. +--------------------------+--------------------------------------------------------+
    21. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
    22. | character_set_connection | utf8 |
    23. | character_set_system | utf8 |
    24. | character_set_results | utf8 |
    25. | character_set_client | utf8 |
    26. | character_set_server | utf8mb4 |
    27. | character_set_database | utf8mb4 |
    28. | character_set_filesystem | binary |
    29. +--------------------------+--------------------------------------------------------+
    30. 8 rows in set (0.00 sec)
    31. mysql> SET CHARACTER SET utf8mb4;
    32. Query OK, 0 rows affected (0.00 sec)
    33. mysql> SHOW VARIABLES LIKE 'character_set%';
    34. +--------------------------+--------------------------------------------------------+
    35. | Variable_name | Value |
    36. +--------------------------+--------------------------------------------------------+
    37. | character_set_connection | utf8mb4 |
    38. | character_set_system | utf8 |
    39. | character_set_results | utf8mb4 |
    40. | character_set_client | utf8mb4 |
    41. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
    42. | character_set_database | utf8mb4 |
    43. | character_set_filesystem | binary |
    44. | character_set_server | utf8mb4 |
    45. +--------------------------+--------------------------------------------------------+
    46. 8 rows in set (0.00 sec)

    MySQL 兼容性

    SET [NAMES|CHARACTER SET] 语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue。

    另请参阅

    • SHOW [GLOBAL|SESSION] VARIABLES
    • SET
    • Character Set Support