2018/05/02 18:36
This afternoon, when inserting data into the MySQL data table, I found that the numbers and English in the MySQL table records can be displayed normally, but the Chinese characters are displayed as '? ', after searching, the main reason is that MySQL's character set is inconsistent. The following is the solution, keep it as a record for future review and consolidation.
Environment: operating environment Windows, compiler eclipse, database MySQL, integrated software wampserver
step one
Modify the MySQL configuration file:
Click the wamp icon, select MySQL/my.ini to open the my.ini file, and modify three places, namely:
The first place: add the sentence default-character-set=utf8
Second place:
Third place:
After the modification is completed, save the modification, click the restart all services option in wamp, and restart the MySQL service. If the modification of the my.ini file is correct, then wamp can be restarted normally. If it cannot be restarted normally, it is because the modification of my.ini is Wrong, pay attention to the three points above.
step two
When creating a table, it is necessary to specify the character set of the table. This mainly means that when writing the SQL statement to create a table in eclipse, it should be written as:
String sql="create table student(name varchar(20)) default charset=utf8;";
step three
Finally check the character encoding status of MySQL
First, you need to enter MySQL from the cmd command. For example, my wamp folder is on the C drive, so the first command is cd C:\wamp\bin\mysql\mysql5.6.17\bin
The second command is mysql -u root -p, which appears after pressing Enter. If there is no password at this time, press the Enter key directly, and then enter the status command to query the status of MySQL.
At this point, look at the table records are already Chinese characters
There are other garbled knowledge about MySQL, and I will add it later when I encounter it.