When installing MySQL, if you do not choose the encoding method, then the system will default to select Latin1 encoding, in the console window of MySQL input show variables like ' char% ' can view the database system's default encoding set, as follows:
We can see that the default encoding of the system is Latin1 encoding, Latin1 is iso-8859-1 alias, some environment writing Latin-1. The ISO-8859-1 encoding is single byte encoded and backwards compatible with ASCII. Chinese encoding is not supported, if you do not explicitly specify the encoding method when creating a database or a table, the database will be encoded by default, and then you will be garbled when inserting Chinese data. But how can we manually modify the default encoding of a database if we have to manually specify the encoding method every time we build a database or a key table?
1. Close the MySQL service, manually stop the MySQL service in the service, or enter net stop MySQL in the cmd window.
2. Then go to your MySQL installation directory to find the My.ini file, if it is an initialized database, then change the MY-DEFAULT.COF to MY.COF, then find the file [MySQL], add the following two lines in its next line
Character_set_server=gbk
init_connect= ' SET NAMES gbk '
or directly in the My.ini directly add the line.
As follows:
3. Save, then reboot, check again and we can see that the system default encoding has changed.
MySQL set the default encoding for the database