Mysql stores special characters

I would like to ask all the great gods, how do you save the special characters of Wechat"s nickname in the database

Mar.28,2021

it is said that you can use utf8mb4, to try


set the character set of the database to utf8mb4, and then execute
set names utf8mb4


utf8mb4


if it is not feasible to change the database, you can transcode and save it, take it out and decode it


.
CREATE TABLE `member_data` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` int(11) NOT NULL COMMENT '',
  `sex` enum('0','1','2') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT ' 0=> 1=> 2=>',
  `nick_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '/',
  `img` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `member_data_member_id_unique` (`member_id`)
) ENGINE=InnoDB AUTO_INCREMENT=125 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

look below
ENGINE=InnoDB AUTO_INCREMENT=125 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
look below
COLLATE=utf8mb4_unicode_ci

set utf8mb4_unicode_ci to store special characters directly


Database character set utf8mb4
Table character set utf8mb4, field needs to be confirmed. if your table was changed halfway instead of utf8mb4, then the previous field code is still the same. You need to manually adjust the field code
Program character set set utf8mb4


if you think it is not possible to set the program character set collate=utf8mb4_unicode_ci, just store it directly base64_encode (). Then parse it in base64_decode ()

Menu