[Flask practice] to solve the problem that mysql database does not support Chinese characters, flaskmysql

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.