【问题标题】:Why I get this strange result: [BLOB - ...]? [duplicate]为什么我得到这个奇怪的结果:[BLOB - ...]? [复制]
【发布时间】:2013-05-12 09:45:33
【问题描述】:

这是我的数据库架构:

Post:
id
title
body
date

Tag:
id
title

Post_Tag:
id
id_post
id_tag

Comment:
id
id_post
body
date

这是我的查询:

SELECT
    Post.id AS post_id,
    Post.title AS post_title,
    Post.body AS post_body,
    GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags,
    COUNT(Comment.id) AS comment_count
FROM Post
LEFT JOIN Comment ON Post.id = Comment.id_post
LEFT JOIN Post_Tag ON Post.id = Post_Tag.id_post
LEFT JOIN Tag ON Tag.id = Post_Tag.id_tag
GROUP BY Post.id
ORDER BY Post.date ASC

谁能告诉我为什么我在标签列下面得到这些奇怪的结果([BLOB - ...])?

id  title           body            tags            comment_count
1   hello guys  blablabla...    [BLOB - 8B]         8
2   hello all   blablabla...    [BLOB - 14B]        3
3   how to tell blablabla...    [BLOB - 8B]         5
4   hello world blablabla...    [BLOB - 5B]         7

【问题讨论】:

标签: mysql sql database


【解决方案1】:

这是一个比较有名的配置问题:你的group_concat_max_len被设置为一个很大的值,迫使MySql使用BLOBs而不是varchars来获取group_concat的结果。

要修复,请在 my.inimy.cnf 文件中将 group_concat_max_len 设置为 512,然后重新启动 MySql。

这是link to a post with more information

【讨论】:

    【解决方案2】:

    替换:

    GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags,
    

    与:

    CAST(GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS CHAR) AS tags,
    

    文档:CAST function

    【讨论】:

      【解决方案3】:

      您也可以使用CONVERT() 并将BLOB 数据转换为utf8

      CONVERT(GROUP_CONCAT(CONCAT(Tag.id, "|", Tag.title) SEPARATOR '#') AS tags USING utf8),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-28
        • 1970-01-01
        • 2021-07-10
        • 2021-11-04
        • 2022-10-23
        相关资源
        最近更新 更多