1. Need to set the input text
format'set names "gb2312"';
or'set names "gbk"';
mysql_query(&mysql,"SET NAMES'GBK'");
if(nback=mysql_real_query(&mysql,p,(unsigned long)strlen(p)))
{
const char *pErr=mysql_error(&mysql);
return false;
}
2. Enter in the mysql input box
ALTER DATABASE database name DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
3. Change all tables and column codes
First generate the change statement for all tables, so that all tables and columns in mysql can be encoded as utf8mb4 in batch
SELECT
CONCAT(
'ALTER TABLE ',
TABLE_NAME,
' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;'
)
FROM
information_schema.`TABLES`
WHERE
TABLE_SCHEMA ='数据库名称';
4. Change the database configuration
The database configuration my.ini or my.cnf, your configuration may not be called this sentence.
Modified to the following configuration:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_general_ci
character-set-server = utf8mb4
Restart mysql after the change