以下查询是否有更短的等效项:(我无法更改表格)。演员是否适用于此?
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
答案 0 :(得分: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)将其更改为您的需求。
答案 1 :(得分:0)
set names utf8;
SELECT old_text AS text, rev_timestamp AS ts, rev_user_text AS user
FROM revisions;
...但如果您在不同的字符集中发送DML,这将会中断。
答案 2 :(得分:0)
最简单的修改方法是修改mysql字符集密钥中的my.ini文件,
default-character-set = utf8
character_set_server = utf8
修改后,重新启动mysql服务,重启服务mysql