V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
Vimax
V2EX  ›  MySQL

mysql 如何根据中文拼音首字母进行中文查询?

  •  
  •   Vimax · 2020-10-20 10:22:45 +08:00 · 3619 次点击
    这是一个创建于 1276 天前的主题,其中的信息可能已经有所发展或是发生改变。

    数据库有个字段保存了中文名称,比如:

    1. 张三
    2. 本山
    3. 赵本山 ...

    现在想通过拼音首字母进行模糊查询:

    比如

    ZS: 可以查询到张三

    BS:可以查找到本山赵本山

    请教,

    在数据库已经存在中文名称的数据,且没有保存中文拼音和首字母拼音的前提下。

    如何使用 mysql 根据中文名称进行拼音首字母查询到数据。

    11 条回复    2022-07-28 21:35:23 +08:00
    Caskia
        1
    Caskia  
       2020-10-20 10:28:14 +08:00   ❤️ 6
    是什么阻碍了你建立拼音和首字母列?
    opengps
        2
    opengps  
       2020-10-20 10:30:32 +08:00 via Android
    这种查询一般需要单独一个列来存储首字母,而不是让数据库具备转换拼音能力
    hbolive
        3
    hbolive  
       2020-10-20 10:59:50 +08:00
    抱歉,开发 MySQL 的人,不认识拼音在这个东东。。
    angeltop
        4
    angeltop  
       2020-10-20 11:11:55 +08:00
    哈哈,这个国产数据库软件应该是支持的。
    lskjdfgl
        5
    lskjdfgl  
       2020-10-20 11:13:21 +08:00   ❤️ 1
    mysql 默认支持拼音查询, 你可以查下文档
    xsm1890
        6
    xsm1890  
       2020-10-20 11:14:04 +08:00
    hahahahahhahahahahaah
    GuangXiN
        7
    GuangXiN  
       2020-10-20 11:27:38 +08:00 via Android
    现在能找到开源的库把汉字转换成拼音吧
    lasuar
        8
    lasuar  
       2020-10-20 11:31:04 +08:00
    别急,这就给 mysql 提 issue
    JaguarJack
        9
    JaguarJack  
       2020-10-20 13:52:15 +08:00
    你在建个拼音列不就好了吗
    zhangysh1995
        10
    zhangysh1995  
       2020-11-02 16:46:06 +08:00
    @lskjdfgl 老哥厉害了,我去看文档了,还真支持 https://dev.mysql.com/doc/mysql-g11n-excerpt/5.7/en/charset-gb18030.html
    gb18030_chinese_ci: The default collation, which supports Pinyin. Sorting of non-Chinese characters is based on the order of the original sort key. The original sort key is GB(UPPER(ch)) if UPPER(ch) exists. Otherwise, the original sort key is GB(ch). Chinese characters are sorted according to the Pinyin collation defined in the Unicode Common Locale Data Repository (CLDR 24). Non-Chinese characters are sorted before Chinese characters with the exception of GB+FE39FE39, which is the code point maximum.
    q344766620
        11
    q344766620  
       2022-07-28 21:35:23 +08:00
    @zhangysh1995 这是按照拼音排序,无法通过拼音搜索数据库。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   943 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:07 · PVG 05:07 · LAX 14:07 · JFK 17:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.