【发布时间】:2014-04-03 05:47:26
【问题描述】:
我有一个问题:
select distinct name from
(
select TABLE_NAME as name from information_schema.TABLES
where TABLE_SCHEMA ='my_db_name'
union
select distinct db_table as name from status
)t
order by name
用mysql(服务器版本:5.1.44)设置
SHOW VARIABLES LIKE 'character_set%';
+--------------------------+------------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /Applications/XAMPP/xamppfiles/share/mysql/charsets/ |
+--------------------------+------------------------------------------------------+
SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
表架构:
CREATE TABLE `status` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`db_table` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`rank` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL,
`style_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `db_table` (`db_table`)
) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
我进一步更改了 my.cnf
[mysqld]
#
#
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
#
我删除了数据库并重新创建了它,现在我收到错误 Illegal mix of collations for operation 'UNION' 。请告诉我我做错了什么。我从 php 和 mysql 命令行遇到同样的问题
这行得通:
select distinct name from
(
select TABLE_NAME collate utf8_unicode_ci as name from information_schema.TABLES
where TABLE_SCHEMA ='my_db_name'
union
select distinct db_table as name from status
)t
order by name
但我不喜欢这种调整,我的问题是:是否有适当的解决方法。正如您所见,mysql 全局设置已设置为正确的排序规则,但信息架构仍在使用 utf8_general_ci 左右?
【问题讨论】:
-
这个问题可能是由于你正在做联合系统生成的表(来自于 myisam 的 information_schema)和用户生成的表。
标签: mysql