0

The usual way to change collation on a mysql table is:

ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

What I want to do is change the tables default collation WITHOUT changing the existing colums collation. How can I accomplish that?

roka
  • 55
  • 7
  • 1
    `ALTER TABLE tbl_name [[DEFAULT] CHARACTER SET charset_name] [COLLATE collation_name]` Just omit the `CONVERT TO` part and set the charset for the table. Existing columns will not be converted. Reference: http://dev.mysql.com/doc/refman/5.7/en/charset-table.html – Pred Jul 05 '16 at 13:26
  • 1
    Grrr... It is not a dup. This talks about the _default_ for a _table_. The other talks about messed up characters (in spite of what the title says). – Rick James Jul 06 '16 at 04:21

1 Answers1

3

ALTER TABLE has two different ways to change a table's character set. The one mentioned in the question is meant to convert all character based columns into the given charset.

Setting the tables DEFAULT character set will not change the character set of the existing columns.

ALTER TABLE tbl_name
  [[DEFAULT] CHARACTER SET charset_name]
  [COLLATE collation_name]

Related doc entries:

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

Pred
  • 8,789
  • 3
  • 26
  • 46