How to set character_set_database and collation_database to utf8 in my.ini?

前端 未结 3 1860
眼角桃花
眼角桃花 2020-12-23 02:12

I\'ve googled a lot about this problem. To sum up, this is what my my.ini looks like:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[cli         


        
相关标签:
3条回答
  • 2020-12-23 02:50

    This actually isn't a setting in the my.cnf (or my.ini in this case). mySQL gets this setting from the database's own collation (when it was created). Inorder to get this inline with the utf8 encoding you want, do this:

    ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
    

    then do a restart on mysql (cant remember if its needed though), followed by a:

    SHOW VARIABLES;
    

    All should be well, Hope that helps!


    side note: i think default-character-set is deprecated now-a-days (mySQL 5.5+) and seems to make the config file fidgety.

    0 讨论(0)
  • 2020-12-23 02:59

    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
    

    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

    0 讨论(0)
  • 2020-12-23 03:03

    I do a summary:

    determine which charset/collations are available

    SHOW CHARSET;
    SHOW COLLATION;
    

    check charset

    SHOW VARIABLES LIKE '%character%';
    SHOW VARIABLES LIKE '%collation%';
    

    set charset (in configure file -> my.cnf)

    [mysqld]
    character-set-server=utf8mb4
    collation-server=utf8mb4_general_ci
    

    check database/table charset

    SHOW CREATE DATABASE databasename;
    SHOW CREATE TABLE tablename;
    

    change the database/table charset

    ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    

    set when create database/table:

    CREATE DATABASE new_db CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;
    CREATE TABLE new_table (id INT) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
    

    Note: I heard that in Mysql utf8 is not the true utf8,utf8mb4 is the real utf8. so, if you have special character that can't save to mysql, maybe you should use utf8mb4 and utf8mb4_general_ci

    0 讨论(0)
提交回复
热议问题