SET [NAMES|CHARACTER SET]

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

语法图

SetNamesStmt:

SetNamesStmt

VariableAssignmentList:

VariableAssignmentList

VariableAssignment:

VariableAssignment

CharsetName:

CharsetName

StringName:

StringName

CharsetKw:

CharsetKw

CharsetNameOrDefault:

CharsetNameOrDefault

示例

  1. SHOW VARIABLES LIKE 'character_set%';
  1. +--------------------------+--------------------------------------------------------+
  2. | Variable_name | Value |
  3. +--------------------------+--------------------------------------------------------+
  4. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
  5. | character_set_connection | utf8mb4 |
  6. | character_set_system | utf8 |
  7. | character_set_results | utf8mb4 |
  8. | character_set_client | utf8mb4 |
  9. | character_set_database | utf8mb4 |
  10. | character_set_filesystem | binary |
  11. | character_set_server | utf8mb4 |
  12. +--------------------------+--------------------------------------------------------+
  13. 8 rows in set (0.01 sec)
  1. SET NAMES utf8;
  1. Query OK, 0 rows affected (0.00 sec)
  1. SHOW VARIABLES LIKE 'character_set%';
  1. +--------------------------+--------------------------------------------------------+
  2. | Variable_name | Value |
  3. +--------------------------+--------------------------------------------------------+
  4. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
  5. | character_set_connection | utf8 |
  6. | character_set_system | utf8 |
  7. | character_set_results | utf8 |
  8. | character_set_client | utf8 |
  9. | character_set_server | utf8mb4 |
  10. | character_set_database | utf8mb4 |
  11. | character_set_filesystem | binary |
  12. +--------------------------+--------------------------------------------------------+
  13. 8 rows in set (0.00 sec)
  1. SET CHARACTER SET utf8mb4;
  1. Query OK, 0 rows affected (0.00 sec)
  1. SHOW VARIABLES LIKE 'character_set%';
  1. +--------------------------+--------------------------------------------------------+
  2. | Variable_name | Value |
  3. +--------------------------+--------------------------------------------------------+
  4. | character_set_connection | utf8mb4 |
  5. | character_set_system | utf8 |
  6. | character_set_results | utf8mb4 |
  7. | character_set_client | utf8mb4 |
  8. | character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |
  9. | character_set_database | utf8mb4 |
  10. | character_set_filesystem | binary |
  11. | character_set_server | utf8mb4 |
  12. +--------------------------+--------------------------------------------------------+
  13. 8 rows in set (0.00 sec)

MySQL 兼容性

SET [NAMES|CHARACTER SET] 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅