同事下午遇到一问题,MySQL 和 Memcached 对于同一个key,不能对应起来。最终原因是:PHP将key写入MySQL数据库之前,没有经过trim()过滤首尾空格(关键是尾部空格),结果:
1、MySQL的varchar、char类型字段,SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中,存储的含有尾部空格的内容“rewinx ”,通过以下三种方式均可查询到:

在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道(http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char):请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此,并且它不受SQL服务器模式的影响。
2、PHP 的 Memcache 扩展,则在set、get时,自动将key中的空格,转换成了半角下划线“_”。当然,直接通过 Memcached 协议来读取,key值“rewinx ”就要写成“rewinx_”了。
示例:testmc.php



1、MySQL的varchar、char类型字段,SELECT .... WHERE 查询时忽略字段的尾部空格。例如varchar类型字段uidcode中,存储的含有尾部空格的内容“rewinx ”,通过以下三种方式均可查询到:

在MySQL手册第“11.4.1. CHAR和VARCHAR类型”节中写道(http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#char):请注意所有MySQL校对规则属于PADSPACE类。这说明在MySQL中的所有CHAR和VARCHAR值比较时不需要考虑任何尾部空格。请注意所有MySQL版本均如此,并且它不受SQL服务器模式的影响。
2、PHP 的 Memcache 扩展,则在set、get时,自动将key中的空格,转换成了半角下划线“_”。当然,直接通过 Memcached 协议来读取,key值“rewinx ”就要写成“rewinx_”了。
示例:testmc.php



asd
2026-6-10 15:05
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... เว็บแทงบอลออนไลน์
setgh
2026-6-11 17:12
Beneficial Write-up, My business is an enormous believer with placing reviews with web-sites to help allow blog site internet writers are aware that they’ve added in anything effective to help online! แทงบอลสด
seo
2026-6-11 22:43
Great compilation — seeing sample patch notes and change logs was informative. Detailed changelogs demonstrate development seriousness and accountability. Real votes aligned with developer consistency. 오피마트 Helpful resource — I found clear guidelines on cross-server trading. Safe cross-server commerce expands market variety responsibly. Real player reviews supported those systems. nano banana Thanks for highlighting servers with clear and fair duel systems. Balanced PvP duels encourage competitive play without toxicity. Real votes corroborated fairness. lemacau link alternatif login
raza
2026-6-13 15:09
Hi there! Nice material, do keep me posted when you post something like this again! I will visit this blog leaps and bounds for more quality posts like it. Thanks... koi toto
sri
2026-6-13 20:30
I've lately began the weblog, the data a person supply on this website offers assisted me personally significantly. Many thanks with regard to all your period & function. AK 게임
raza
2026-6-14 16:05
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. สมัครแทงบอล
RAZA
2026-6-17 15:36
I've lately began the weblog, the data a person supply on this website offers assisted me personally significantly. Many thanks with regard to all your period & function. 연산동풀싸롱
dfsfsd
2026-6-19 06:45
I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! koitoto
aasd
2026-6-19 13:29
Hello! I recently would want to provide a enormous thumbs up for that excellent information you’ve got here about this post. I’ll be coming back to your website to get more soon. <a href="https://urbantick.org/">slot online</a>
sasd
2026-6-20 18:51
Thanks for the blog post buddy! Keep them coming... download cisco vpn for windows
分页: 5/5
1 2 3 4 5
1 2 3 4 5
轻量级开源简单队列服务 HTTPSQS 1.3 版本发布
每天,纵贯京城

2010-7-6 18:42 | by







