1. length:占用字节
    2. char_length:共有多个字符
    3. [root@localhost][(none)]: \s
    4. --------------
    5. mysql Ver 14.14 Distrib 5.7.27, for linux-glibc2.12 (x86_64) using EditLine wrapper
    6. Connection id: 11782
    7. Current database:
    8. Current user: root@localhost
    9. SSL: Not in use
    10. Current pager: stdout
    11. Using outfile: ''
    12. Using delimiter: ;
    13. Server version: 5.7.27-log MySQL Community Server (GPL)
    14. Protocol version: 10
    15. Connection: Localhost via UNIX socket
    16. Server characterset: utf8mb4
    17. Db characterset: utf8mb4
    18. Client characterset: utf8mb4
    19. Conn. characterset: utf8mb4
    20. UNIX socket: /mysql/tmp/mysql.sock
    21. Uptime: 6 days 3 hours 38 min 4 sec
    22. Threads: 2 Questions: 183301 Slow queries: 173 Opens: 8061 Flush tables: 7 Open tables: 45 Queries per second avg: 0.344
    23. --------------
    24. [root@localhost][(none)]: select length('我'),char_length('我');
    25. +---------------+--------------------+
    26. | length('我') | char_length('我') |
    27. +---------------+--------------------+
    28. | 3 | 1 |
    29. +---------------+--------------------+
    30. 1 row in set (0.00 sec)
    31. 转为16进制编码
    32. [root@localhost][(none)]: select hex('我');
    33. +------------+
    34. | hex('我') |
    35. +------------+
    36. | E68891 |
    37. +------------+
    38. 1 row in set (0.00 sec)
    39. [root@localhost][(none)]: select 0xE68891;
    40. +----------+
    41. | 0xE68891 |
    42. +----------+
    43. | |
    44. +----------+
    45. 1 row in set (0.00 sec)
    46. 不同字符集结果不一样
    47. [root@localhost][(none)]: set character_set_client=latin1;
    48. Query OK, 0 rows affected (0.00 sec)
    49. [root@localhost][(none)]: select length('我'),char_length('我');
    50. +-------------------+------------------------+
    51. | length('我') | char_length('我') |
    52. +-------------------+------------------------+
    53. | 7 | 3 |
    54. +-------------------+------------------------+
    55. 1 row in set (0.00 sec)
    56. [root@localhost][(none)]: select hex('我');
    57. +----------------+
    58. | hex('我') |
    59. +----------------+
    60. | C3A6CB86E28098 |
    61. +----------------+
    62. 1 row in set (0.00 sec)