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 · Oct 20, 2020 · 4869 views
    This topic created in 2050 days ago, the information mentioned may be changed or developed.

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

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

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

    比如

    ZS: 可以查询到张三

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

    请教,

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

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

    11 replies    2022-07-28 21:35:23 +08:00
    Caskia
        1
    Caskia  
       Oct 20, 2020   ❤️ 6
    是什么阻碍了你建立拼音和首字母列?
    opengps
        2
    opengps  
       Oct 20, 2020 via Android
    这种查询一般需要单独一个列来存储首字母,而不是让数据库具备转换拼音能力
    hbolive
        3
    hbolive  
       Oct 20, 2020
    抱歉,开发 MySQL 的人,不认识拼音在这个东东。。
    angeltop
        4
    angeltop  
       Oct 20, 2020
    哈哈,这个国产数据库软件应该是支持的。
    lskjdfgl
        5
    lskjdfgl  
       Oct 20, 2020   ❤️ 1
    mysql 默认支持拼音查询, 你可以查下文档
    xsm1890
        6
    xsm1890  
       Oct 20, 2020
    hahahahahhahahahahaah
    GuangXiN
        7
    GuangXiN  
       Oct 20, 2020 via Android
    现在能找到开源的库把汉字转换成拼音吧
    freemoon
        8
    freemoon  
       Oct 20, 2020
    别急,这就给 mysql 提 issue
    akagishigeru
        9
    akagishigeru  
       Oct 20, 2020
    你在建个拼音列不就好了吗
    zhangysh1995
        10
    zhangysh1995  
       Nov 2, 2020
    @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  
       Jul 28, 2022
    @zhangysh1995 这是按照拼音排序,无法通过拼音搜索数据库。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1102 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 5414617a · 49ms · UTC 18:19 · PVG 02:19 · LAX 11:19 · JFK 14:19
    ♥ Do have faith in what you're doing.