How to connect to MySQL using UTF8 within a perl script?

后端 未结 1 891
轻奢々
轻奢々 2021-01-03 23:47

In a nutshell:

Within a Perl-Script: How do I connect to MySQL in a way that allows to transmit the four-byte unicode character U+1F61C (\"

相关标签:
1条回答
  • 2021-01-04 00:13

    The problem is with the SET NAMES utf8 command. In MySQL the utf8 character set is not truly utf8, it supports characters up 3 bytes only and the character in question has 4 bytes:

    The utf8 character set in MySQL has these characteristics:

    • No support for supplementary characters (BMP characters only).

    • A maximum of three bytes per multibyte character.

    The true utf8 is the utf8mb4 that you use as character set in the field itself. So, use SET NAMES utf8mb4

    So from Perl you should use {mysql_enable_utf8mb4 => 1} instead of {mysql_enable_utf8 => 1}.

    0 讨论(0)
提交回复
热议问题