Mysql5 character set coding problem solved

  • 2020-05-09 19:27:06
  • OfStack

The standard we follow is that the encoding of databases, tables, fields, and pages or text should be unified
Many of the mysql database tools (with the exception of phpmyadmin, which I use occasionally and which is very powerful and slow) do not support specifying the database encoding at creation time. You can certainly fix this by changing my.ini, but you will need to restart mysql, but it is more efficient to use the following statement
GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
Note: if it is not set through the my.ini configuration file, it is only valid in the current state and will not be valid when the database service is restarted. Therefore, if you want to modify the my.ini file to avoid chaos, the database code can specify UTF8 when creating the database, as follows:
|character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8
Note that this configuration | character_set_server | latin1 cannot be set to UTF8
You can still have garbled code when you interact.
Only when my.ini is set to UTF8 will all be changed to UTF8
-------------------------
mysql sets the encoding command
SET character_set_client = utf8;
SET character_set_connection = utf8;
SET character_set_database = utf8;
SET character_set_results = utf8; It's useful to note here that */
SET character_set_server = utf8;
SET collation_connection = utf8_bin;
SET collation_database = utf8_bin;
SET collation_server = utf8_bin;
Default encoding is configured in my.ini
default-character-set=utf8
Connection database setup encoding
jdbc:mysql://192.168.0.5:3306/test?characterEncoding=utf8
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * java and mysq code corresponding to the * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
The common code in java is UTF-8; GBK; GB2312; ISO - 8859-1.
Corresponding to the code utf8 in mysql database; gbk; gb2312; latin1

---------------------------
Database connection string of the specified character set URL = jdbc: mysql: / / yourIP/college? user = root & password = yourPassword & useUnicode = true & characterEncoding = gbk

Don't try to modify character_set_server by sql, is that temporary, or do you want to modify my.ini or my.cnf under linux

[mysqld] 
...... 
character_set_server=utf8 
default-character-set=utf8

Related articles: