mysql的字符串匹配 需求表數據如下: Java代碼 mysql> select * from test; +----+-------+ | id | name | +----+-------+ | 1 | abc** | +----+-------+ 1 row in set (0.00 sec) 我想匹配 abcde,也就是一個*代表一個字符 分析: 在正則中*代表0個或者多個,因此此處的存儲有問題,應該存儲.或者_那麼查詢sql可以通過like和REGEXP 來實現 結論: 1.采用like Java代碼 mysql> select * from test where 'abcde' like replace(name,'*','_'); +----+-------+ | id | name | +----+-------+ | 1 | abc** | +----+-------+ 1 row in set (0.01 sec) 先替換成_然後在like 匹配 2.采用REGEXP Java代碼 mysql> select * from test where 'abcde' regexp replace(name,'*','.'); +----+-------+ | id | name | +----+-------+ | 1 | abc** | +----+-------+ 1 row in set (0.02 sec) 替換成.然後在匹配