How to make MySQL handle UTF-8 properly

前端 未结 14 2784
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:38

One of the responses to a question I asked yesterday suggested that I should make sure my database can handle UTF-8 characters correctly. How I can do this with MySQL?

14条回答
  •  爱一瞬间的悲伤
    2020-11-22 07:06

    Your answer is you can configure by MySql Settings. In My Answer may be something gone out of context but this is also know is help for you.
    how to configure Character Set and Collation.

    For applications that store data using the default MySQL character set and collation (latin1, latin1_swedish_ci), no special configuration should be needed. If applications require data storage using a different character set or collation, you can configure character set information several ways:

    • Specify character settings per database. For example, applications that use one database might require utf8, whereas applications that use another database might require sjis.
    • Specify character settings at server startup. This causes the server to use the given settings for all applications that do not make other arrangements.
    • Specify character settings at configuration time, if you build MySQL from source. This causes the server to use the given settings for all applications, without having to specify them at server startup.

    The examples shown here for your question to set utf8 character set , here also set collation for more helpful(utf8_general_ci collation`).

    Specify character settings per database

      CREATE DATABASE new_db
      DEFAULT CHARACTER SET utf8
      DEFAULT COLLATE utf8_general_ci;
    

    Specify character settings at server startup

    [mysqld]
    character-set-server=utf8
    collation-server=utf8_general_ci
    

    Specify character settings at MySQL configuration time

    shell> cmake . -DDEFAULT_CHARSET=utf8 \
               -DDEFAULT_COLLATION=utf8_general_ci
    

    To see the values of the character set and collation system variables that apply to your connection, use these statements:

    SHOW VARIABLES LIKE 'character_set%';
    SHOW VARIABLES LIKE 'collation%';
    

    This May be lengthy answer but there is all way, you can use. Hopeful my answer is helpful for you. for more information http://dev.mysql.com/doc/refman/5.7/en/charset-applications.html

提交回复
热议问题