简体   繁体   中英

MySql table columns have different CHARSET and COLLATION even when SELECT data is from the same source table and column?

In creating a simple (temporary) MySQL table, taking data from the same column of the same source table, the two resulting columns wind up with different CHARACTER SET and resulting default COLLATION settings:

mysql> CREATE TABLE tempDates
       SELECT SUBDATE(MAX(EventDate), INTERVAL 90 DAY) AS StartDate,
       MAX(EventDate) AS EndDate FROM james_bond_007
       WHERE EventCategory = 'Successful_Kills';

Here is the output showing the resulting table structures:

mysql> SHOW CREATE TABLE tempDates;

CREATE TABLE `tempDates` (
  `StartDate` varchar(29) CHARACTER SET utf8 DEFAULT NULL,
  `EndDate` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 

I ran an alter table command, but NOTHING changed:

ALTER TABLE tempdates CHARACTER SET latin1 COLLATE latin1_swedish_ci; 

From a curiosity standpoint, I want to know why this happens, and from a practical standpoint, how do I make this not happen?

The result I want is for all columns to have the server defaults: CHARACTER SET latin1 COLLATE latin1_swedish_ci

Even better would be a way to impose the server defaults on all columns so I don't have to type more than I want to in future queries of this type.

@Rick James This solved my problem so I want to mark it answered.

If you've a moment, perhaps an explanation as to why? (gives me another excuse to upvote you and accept your answer)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM