Home  >  Article  >  Database  >  MySQL database does not support Chinese solutions

MySQL database does not support Chinese solutions

黄舟
黄舟Original
2017-07-27 15:41:232176browse

Continuing from the previous article, after solving the mysql+flask environment configuration problem, a 1366 error will be reported when going to the Chinese string in the database, prompting incorrect characters. Then I found that the default mysql uses the Latin1 character set, which does not support Chinese.

If you want to support Chinese, you need to set the mysql character set.

As we all know, utf-8 is possible, and gbk is no problem. For scalability, UTF-8 encoding is selected. The idea is as follows:

1. Close the mysql service

2. sudo gedit <span class="pln"><span class="pun">/<span class="pln">etc<span class="pun">/<span class="pln">mysql<span class="pun">/ <code class="prettyprint"><span class="pln"><span class="kwd">my<span class="pun">.<span class="pln">cnf Use administrator rights to edit the configuration file, add the following content and save it (tip: do not save trouble and use permission instructions to modify the read and write permissions of ubuntu system files , the author once changed the permissions of all system files to 777. Although it is more convenient to use the graphical interface to access system files, the system is broken...) </span></span></span></span>

# ##

 [mysqld]
    character_set_server = utf8 
    [client]
    default-character-set = utf8
    [mysql]
     default-character-set = utf8

<span class="com"><span class="pln"><span class="pun"><span class="pln"><span class="com"><span class="pln"><span class="kwd"><span class="pun"><span class="pln"><span class="pun"><span class="kwd"><span class="pln"><span class="pun"><span class="pln"></span></span></span></span></span></span></span></span></span></span></span></span></span></span>3. Restart the mysql service
4. The database at this time has used the utf-8 character set by default, but the database you created before is still the Latin1 character set. You need to delete the previous database and recreate it. A new one, at this time the database will use the utf-8 character set by default.

5. Test it, Chinese can also be stored in the database!

The above is the detailed content of MySQL database does not support Chinese solutions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn