简体   繁体   English

即使SELECT数据来自同一源表和列,MySql表列也具有不同的CHARSET和COLLATION?

[英]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表时,从同一源表的同一列中获取数据,最后得到的两个列将具有不同的CHARACTER SET和默认的COLLATION设置:

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命令,但没有改变:

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 我想要的结果是所有列都具有服务器默认值: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. @Rick James这解决了我的问题,所以我想标记为已回答。

If you've a moment, perhaps an explanation as to why? 如果您有时间,也许可以解释一下原因? (gives me another excuse to upvote you and accept your answer) (给我另一个借口支持您并接受您的回答)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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