diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 703cc59d9a4..dee7433404f 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -343,6 +343,22 @@ t1 CREATE TABLE `t1` ( `a` char(10) character set latin1 default NULL ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 drop table t1; +create table t1 (myblob longblob,mytext longtext) +default charset latin1 collate latin1_general_cs; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `myblob` longblob, + `mytext` longtext character set latin1 collate latin1_general_cs +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 character set latin2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `myblob` longblob, + `mytext` longtext character set latin2 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; CREATE TABLE t1 ( Host varchar(16) binary NOT NULL default '', User varchar(16) binary NOT NULL default '', diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 8da017e8acb..bb174c0225a 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -183,6 +183,17 @@ show create table t1; drop table t1; +# +# Bug#2821 +# Test that table CHARACTER SET does not affect blobs +# +create table t1 (myblob longblob,mytext longtext) +default charset latin1 collate latin1_general_cs; +show create table t1; +alter table t1 character set latin2; +show create table t1; +drop table t1; + # # Test ALTER TABLE ENABLE/DISABLE keys when things are locked # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f4440f27945..8011809d6ab 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -470,9 +470,11 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, sql_field->charset= create_info->default_table_charset; /* table_charset is set in ALTER TABLE if we want change character set - for all varchar/char columns + for all varchar/char columns. + But the table charset must not affect the BLOB fields, so don't + allow to change my_charset_bin to somethig else. */ - if (create_info->table_charset) + if (create_info->table_charset && sql_field->charset != &my_charset_bin) sql_field->charset= create_info->table_charset; sql_field->create_length_to_internal_length();