2

以下查询是否有任何更短的等效项:(我无法更改表)。演员表运算符在这里适用吗?

select convert(old_text using utf8) as text,
   convert(rev_timestamp using utf8) as ts,
   convert(rev_user_text using utf8) as user from revision;

更新:表架构是:

CREATE TABLE `revision` (
    `rev_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `rev_page` INT(10) UNSIGNED NOT NULL,
    `rev_text_id` INT(10) UNSIGNED NOT NULL,
    `rev_comment` TINYBLOB NOT NULL,
    `rev_user` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    `rev_user_text` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
    `rev_timestamp` BINARY(14) NOT NULL DEFAULT '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0',
`old_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`old_text` MEDIUMBLOB NOT NULL,
`old_flags` TINYBLOB NOT NULL,
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
4

3 回答 3

0

最好的方法是更改​​您的表格并为您需要的列设置 utf8,而不是每次都转换它们

    ALTER TABLE t MODIFY old_text CHAR(50) CHARACTER SET utf8;
    ALTER TABLE t MODIFY rev_timestamp CHAR(50) CHARACTER SET utf8;
    ALTER TABLE t MODIFY rev_user_text CHAR(50) CHARACTER SET utf8;

然后正常选择它们。

select old_text  as text, rev_timestamp  as ts, rev_user_text as user 
from revision;

注意:关于 char(50) 将其更改为您的需要。

于 2013-09-23T11:58:32.253 回答
0
set names utf8;

SELECT old_text AS text, rev_timestamp AS ts, rev_user_text AS user
FROM revisions;

...但是如果您以不同的字符集发送 DML,这将中断。

于 2013-09-23T11:59:07.703 回答
0

最简单的修改方法,就是修改mysql字符集key中的my.ini文件,

default-character-set = utf8 
character_set_server = utf8

修改后重启mysql服务,service mysql restart

于 2013-09-23T12:00:43.570 回答