How to change the connection collation of Mysql

后端 未结 2 1133
走了就别回头了
走了就别回头了 2021-02-13 04:19

How can I change connection collation of mysql database?

I am using Mysql workbench 5.5 and mysql 5.5 in ubuntu 14.

When I execute a stored procedure, an error o

相关标签:
2条回答
  • 2021-02-13 04:48

    Look into your my.cnf, find the contents below near collation_server:

    [mysqld]
    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci 
    skip-character-set-client-handshake
    

    Then change your collation variables to:

    collation_connection    utf8_unicode_ci
    collation_server        latin1_swedish_ci
    

    Remember to restart MySQL server service.

    For DB collation, you can use the following SQL:

    ALTER DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;
    

    or you can do it at Alter database screen in MySQL Workbench (always update this to the latest version!)

    0 讨论(0)
  • 2021-02-13 04:49

    Firstly, I think the error message is because of the collation of stored procedure (connection) doesn't match the table. But I was wrong, the reason for the error is because of the collation of the column doesn't match the collation of the table.

    I want to change to collation of column to 'utf8_unicode_ci' in my case. So I have run this statement:

    alter table <YourTableName> 
        MODIFY <YourColumnName> VARCHAR(XXX) COLLATE 'utf8_unicode_ci';
    

    Please be aware that change of collation may result in data loss. For me, General -> Unicode, with all English in varchar column. There is none.

    Further reading: http://dev.mysql.com/doc/refman/5.7/en/charset-column.html

    http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html

    http://dev.mysql.com/doc/refman/5.7/en/charset-database.html

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