【问题标题】:MySQL convert column from Latin1 to UTF8MySQL将列从Latin1转换为UTF8
【发布时间】:2020-12-02 08:36:07
【问题描述】:

我的旧数据库备份曾经在某些列中包含 UTF-8 字符,但我想它已导出为 latin1 字符集。

现在我对某些包含“西里尔文 (utf8) 字符/文本”的列有疑问:http://prntscr.com/vu4uql

我能够使用以下命令将几列转换为 UTF8 :

UPDATE jos_content SET title = CONVERT(CAST(CONVERT(title USING latin1) AS BINARY) USING utf8);

列:“title”、“introtext”现在已转换并显示“Cyrillic (utf8) characters/text”

但我只有一列“全文”有问题,当我尝试在 SQL > phpmyadmin 中使用上述命令时,我收到以下错误:

Error
Static analysis:

18 errors were found during analysis.

Unrecognized keyword. (near "fulltext" at position 23)
Unexpected token. (near "=" at position 32)
Unrecognized keyword. (near "CONVERT" at position 34)
Unexpected token. (near "(" at position 41)
Unrecognized keyword. (near "CAST" at position 42)
Unexpected token. (near "(" at position 46)
Unrecognized keyword. (near "CONVERT" at position 47)
Unexpected token. (near "(" at position 54)
Unrecognized keyword. (near "fulltext" at position 55)
Unrecognized keyword. (near "USING" at position 64)
Unexpected token. (near "latin1" at position 70)
Unexpected token. (near ")" at position 76)
Unrecognized keyword. (near "AS" at position 78)
Unrecognized keyword. (near "BINARY" at position 81)
Unexpected token. (near ")" at position 87)
Unrecognized keyword. (near "USING" at position 89)
Unexpected token. (near "utf8" at position 95)
Unexpected token. (near ")" at position 99)
SQL query:

UPDATE jos_content SET fulltext = CONVERT(CAST(CONVERT(fulltext USING latin1) AS BINARY) USING utf8)

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'fulltext = CONVERT(CAST(CONVERT(fulltext USING latin1) AS BINARY) USING utf8)' at line 1

我怎样才能修复/将此列转换为上一列?

【问题讨论】:

    标签: mysql phpmyadmin


    【解决方案1】:

    根据您发布的内容,问题在于您使用fulltext 作为列名,但它也是用于在创建或修改表结构时定义索引类型的保留字。

    用反引号将每个出现的单词 fulltext 括起来,如下所示:

    UPDATE jos_content SET `fulltext` = CONVERT(CAST(CONVERT(`fulltext` USING latin1) AS BINARY) USING utf8)

    出于这个原因,始终在反引号中包含数据库、表和列名(以及其他任何内容,如视图、过程等)是一个有点帮助的想法。

    顺便说一句,https://github.com/phpmyadmin/phpmyadmin/wiki/Garbled_data 对解码乱码数据的其他解决方案有一些提示,但我相信您的问题仅限于反引号,当您解决该问题时,您的查询应该可以正常工作。

    【讨论】:

    • Tnx for answer ,我在几个小时后意识到“全文”是保留字,所以找到了一种将列更改为另一个词的方法,使用前面的“命令”交换字符,然后我将列名改回 "fulltext" 。 Tnx 反正
    猜你喜欢
    • 2011-05-03
    • 1970-01-01
    • 2015-04-09
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 2010-12-04
    相关资源
    最近更新 更多