Encoding Problem of mysql5.7. 21 utf8 in Mac Environment and Its Solution
- 2021-10-11 19:52:09
- OfStack
1. Goal: Change the value of character_set_server for mysql from latin1 to utf8
Temporary: SET character_set_server=utf8 is sufficient, once.
Persistence: You need to change the configuration file, see Step 2.
2. There is no configuration file in support-files for mysql 5.7. 21.
New my. cnf. You can directly change the extension to cnf after building a text file. Open with Xcode or subline is preferred. The contents are as follows:
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
3. Copy my. cnf to/private/etc/
cp /usr/local/mysql/support-files/my.cnf /private/etc/my.cnf
Note: In fact,/etc is a body double of/private/etc, and can be copied to both.
4. Restart the mysql server and enter mysql
mysql>show variables like '%char%';
It can be found that the encoding values are changed to utf8.
At this time, rebuild the database and build the table, and the imported data can display Chinese normally.
Summarize