If your table or column is different from the default MySQL, in my case latin1_sweedish_ci, it will print the mapping to the column. See the following experiments demonstrating this.
To set the default character set, see this post .
First, let's create a database with two tables. One table has a character set and a mapping job.
mysql> create database SO; mysql> use SO; mysql> create table test1 (col1 text, col2 text); mysql> create table test2 (col1 text, col2 text) character set utf8 collate utf8_unicode_ci;
Now check show create table to see what it looks like:
mysql> show create table test1; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test1 | CREATE TABLE `test1` ( `col1` text, `col2` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1 +-------+-----------------+ 1 row in set (0.00 sec) mysql> show create table test2; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test2 | CREATE TABLE `test2` ( `col1` text COLLATE utf8_unicode_ci, `col2` text COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec)
We can see that test2 already looks like the columns are specific and not used by default. I suspect that if it is different from MySQL by default, it will list it, and not different from the default table. Now let's see how they look in the information_schema database.
mysql> select table_schema, table_name, table_collation from information_schema.tables where table_schema = 'SO'; +--------------+------------+-------------------+ | table_schema | table_name | table_collation | +--------------+------------+-------------------+ | SO | test1 | latin1_swedish_ci | | SO | test2 | utf8_unicode_ci | +--------------+------------+-------------------+ 2 rows in set (0.00 sec) mysql> select table_schema, table_name, column_name, character_set_name, collation_name from information_schema.columns where table_schema = 'SO'; +--------------+------------+-------------+--------------------+-------------------+ | table_schema | table_name | column_name | character_set_name | collation_name | +--------------+------------+-------------+--------------------+-------------------+ | SO | test1 | col1 | latin1 | latin1_swedish_ci | | SO | test1 | col2 | latin1 | latin1_swedish_ci | | SO | test2 | col1 | utf8 | utf8_unicode_ci | | SO | test2 | col2 | utf8 | utf8_unicode_ci | +--------------+------------+-------------+--------------------+-------------------+ 4 rows in set (0.00 sec)
It appears that the columns have a specific character set and collation, regardless of whether we specified it. Let's upgrade test1 to the preferred character set and sort and see what happens.
mysql> ALTER TABLE test1 CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table test1; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test1 | CREATE TABLE `test1` ( `col1` mediumtext COLLATE utf8_unicode_ci, `col2` mediumtext COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec) mysql> show create table test2; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test2 | CREATE TABLE `test2` ( `col1` text COLLATE utf8_unicode_ci, `col2` text COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec)
Now they both put the mapping in the show create table statement. Let me check schema information again.
mysql> select table_schema, table_name, table_collation from information_schema.tables where table_schema = 'SO'; +--------------+------------+-----------------+ | table_schema | table_name | table_collation | +--------------+------------+-----------------+ | SO | test1 | utf8_unicode_ci | | SO | test2 | utf8_unicode_ci | +--------------+------------+-----------------+ 2 rows in set (0.00 sec) mysql> select table_schema, table_name, column_name, character_set_name, collation_name from information_schema.columns where table_schema = 'SO'; +--------------+------------+-------------+--------------------+-----------------+ | table_schema | table_name | column_name | character_set_name | collation_name | +--------------+------------+-------------+--------------------+-----------------+ | SO | test1 | col1 | utf8 | utf8_unicode_ci | | SO | test1 | col2 | utf8 | utf8_unicode_ci | | SO | test2 | col1 | utf8 | utf8_unicode_ci | | SO | test2 | col2 | utf8 | utf8_unicode_ci | +--------------+------------+-------------+--------------------+-----------------+ 4 rows in set (0.00 sec)
Everything seems to be about the same. But what happens when we add an extra column to both tables?
mysql> alter table test1 add column col3 text; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table test2 add column col3 text; Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table test1; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test1 | CREATE TABLE `test1` ( `col1` mediumtext COLLATE utf8_unicode_ci, `col2` mediumtext COLLATE utf8_unicode_ci, `col3` text COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec) mysql> show create table test2; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test2 | CREATE TABLE `test2` ( `col1` text COLLATE utf8_unicode_ci, `col2` text COLLATE utf8_unicode_ci, `col3` text COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec)
In both cases, they collected the sort from the table. Therefore, there should not be much concern about the column added later due to the impact. Let check schema information again ...
mysql> select table_schema, table_name, table_collation from information_schema.tables where table_schema = 'SO'; +--------------+------------+-----------------+ | table_schema | table_name | table_collation | +--------------+------------+-----------------+ | SO | test1 | utf8_unicode_ci | | SO | test2 | utf8_unicode_ci | +--------------+------------+-----------------+ 2 rows in set (0.00 sec) mysql> select table_schema, table_name, column_name, character_set_name, collation_name from information_schema.columns where table_schema = 'SO'; +--------------+------------+-------------+--------------------+-----------------+ | table_schema | table_name | column_name | character_set_name | collation_name | +--------------+------------+-------------+--------------------+-----------------+ | SO | test1 | col1 | utf8 | utf8_unicode_ci | | SO | test1 | col2 | utf8 | utf8_unicode_ci | | SO | test1 | col3 | utf8 | utf8_unicode_ci | | SO | test2 | col1 | utf8 | utf8_unicode_ci | | SO | test2 | col2 | utf8 | utf8_unicode_ci | | SO | test2 | col3 | utf8 | utf8_unicode_ci | +--------------+------------+-------------+--------------------+-----------------+ 6 rows in set (0.00 sec)
Yes. Everything seems to work the same. But what about this hypothesis about it, only if it differs from MySQL by default, and not by default? Let set test1 go back to what it was.
mysql> ALTER TABLE test1 CONVERT TO CHARACTER SET latin1 COLLATE latin1_swedish_ci; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table test1; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test1 | CREATE TABLE `test1` ( `col1` mediumtext, `col2` mediumtext, `col3` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1 +-------+-----------------+ 1 row in set (0.00 sec)
It seems we are looking as soon as we started. Now, to demonstrate that this is the default MySQL value, and not just the default database, set the default value for the database.
mysql> Alter database SO default character set utf8 collate utf8_unicode_ci; Query OK, 1 row affected (0.00 sec) mysql> show create table test1; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test1 | CREATE TABLE `test1` ( `col1` mediumtext, `col2` mediumtext, `col3` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1 +-------+-----------------+ 1 row in set (0.00 sec) mysql> show create table test2; +-------+-----------------+ | Table | Create Table +-------+-----------------+ | test2 | CREATE TABLE `test2` ( `col1` text COLLATE utf8_unicode_ci, `col2` text COLLATE utf8_unicode_ci, `col3` text COLLATE utf8_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +-------+-----------------+ 1 row in set (0.00 sec)
As you can see, test1 still looks like when we are just starting, and show create table not dependent on the default database.