[Flask practice] to solve the problem that mysql database does not support Chinese characters, flaskmysql
In the previous article, after the mysql + flask environment configuration problem is solved, a 1366 error will be reported to the Chinese character string in the data inventory, prompting incorrect characters. Then we found that the default mysql uses the Latin1 character set, which isChinese is not supported.
To support Chinese characters, you need to set the mysql character set.
We all know that UTF-8 is okay, and gbk is okay. For the sake of scalability, we should select UTF-8 encoding. The idea is as follows:
1. Disable the mysql Service
Ii. sudo gedit/Etc/mysql/My. cnf uses the Administrator permission to edit the configuration file, add the following content and save it (Note: Do not use the permission command to modify the read and write permissions of ubuntu system files, I once changed all the system file permissions to 777. Although it is easier to access the system file through a graphical interface, the system is broken ......)
[mysqld]
character_set_server = utf8
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
Iii. Restart the mysql Service
4. At this time, the database uses the UTF-8 character set by default, but the database you created is still the Latin1 character set. You need to delete the previous database and create a new one, in this case, the database uses the UTF-8 character set by default.
5. Test whether Chinese characters can be saved to the database!
Reference: http://ju.outofmemory.cn/entry/169992