Home  >  Q&A  >  body text

mysql 插入的数据是乱码

黄舟黄舟2717 days ago448

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 13:30:37

    This is caused by the inconsistency between the encoding of the client and the encoding of the database.
    Are you typing from the terminal?
    For example, the encoding in your terminal is GBK, and although the server database uses UTF-8 encoding, it can recognize the GBK encoding data notified to the server and automatically convert it to UTF-8 for storage. You can use the following statement to quickly set the encoding set related to the client:
    set names gbk;
    After the setting is completed, the garbled problem of inserting data or displaying data on the client can be solved, but we will soon discover this The formal setting will only be effective in the current window. When the CMD client is reopened after the window is closed, garbled characters will appear. So, how to make a once-and-for-all setting? There is a my.conf configuration file in the MySQL installation directory. By modifying this configuration file, you can solve the garbled problem once and for all. In this configuration file [mysql] is related to the client configuration, and [mysqld] is related to the server configuration. The default configuration is as follows:

    [mysql]
    default-character-set=utf8
    [mysqld]
    character-set-server=utf8

    At this time, you only need to change the default encoding default-character-set=utf8 to default-character-set=gbk and restart the MySQL service.

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:30:37

    Before importing set names utf8;

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:30:37

    This is usually a problem of inconsistent character set settings. Try setting it through the editor or setting it in the code

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:30:37

    When I first learned to write programs, various garbled characters appeared. When the database was imported, garbled characters appeared. After the database was no longer garbled, the data read from the database displayed garbled characters and various garbled characters. Later, they were all unified to utf8.
    The database was set to utf8. ,
    When importing the file, the text type of the file is also utf8.
    When importing through code, the charset is also set to utf8.
    The file format edited by the editor is utf8.
    The charset of the web page is also utf8.

    reply
    0
  • Cancelreply