For the MySQL database garbled problem, there are two cases:
1. MySQL database encoding problem (set when building the library).
2. Link the URL encoding setting of the MySQL database.
For the first question, the current personal discovery can only be solved by re-building the library, when the database is built, select the UTF-8 character set. I tried to modify the existing database character set to Uft
-8, but does not work at all, the inserted Chinese is still garbled (Chinese display as:??? )。 When the library is rebuilt with the character set UTF-8, Chinese is displayed normally.
For the second question, this is the case: when I built the library, the default character set for the database was UTF-8, and it was perfectly normal to insert the Chinese display directly via MySQL Workbench. But when inserting data using Mybaits, Chinese is displayed as "???" Such a garbled. But the Chinese obtained from the database is not garbled. Tracking database operations, the Chinese in the SQL statement is still normal, but after inserting into the MySQL database is garbled, so the judgment may be a database connection problem. Later on the Internet to find the information, found that the MySQL database can indeed set the connection string encoding method, as follows:
Jdbc:mysql://127.0.0.1:3306/test? Useunicode=true&characterencoding=utf8
After adding the useunicode=true&characterencoding=utf8 parameter, inserting Chinese is normal.
The purpose of the addition is to specify the encoding and decoding format of the characters.
For example, suppose that the MySQL database is GBK encoded (or possibly others, such as Ubuntu under Latin1), and the project database is UTF-8 encoded. If Useunicode=true&characterencoding=utf-8 is added at this time, then there are two aspects of the function:
1. When data is stored:
when storing the project data, the database decodes the data into bytecode using the UTF-8 format, and then the decoded bytecode is reused in the database using the GBK encoding.
2. When data is taken:
when fetching data from the database, the database will first decode the data in the database into bytecode in GBK format, then encode the decoded bytecode again in UTF-8 format, and then return the data to the client.
MySQL garbled in two cases