# Normal for mysql to strip trailing spaces?

**URL:** <https://forums.percona.com/t/normal-for-mysql-to-strip-trailing-spaces/133>\
**Category:** Other MySQL® Questions\
**Created:** [November 26, 2006, 1:17am UTC](https://forums.percona.com/t/normal-for-mysql-to-strip-trailing-spaces/133 "2006-11-26T01:17:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carpii](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@carpii](https://forums.percona.com/u/carpii)\
**Post date:** [November 26, 2006, 1:17am UTC](https://forums.percona.com/t/normal-for-mysql-to-strip-trailing-spaces/133/1 "2006-11-26T01:17:08Z")

</div>

I have a table users, with u\_username field varchar(20)  
Im using mysql v5

select u\_userid from users where u\_username = ‘carpii’  
returns user id 17

select u\_userid from users where u\_username = 'carpii ’  
also returns user id 17

Is this normal behavior for mysql?  
Can it be changed?

---

<div class="post-metadata">

**Author:** ![bitrockers](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@bitrockers](https://forums.percona.com/u/bitrockers)\
**Post date:** [November 26, 2006, 9:59am UTC](https://forums.percona.com/t/normal-for-mysql-to-strip-trailing-spaces/133/2 "2006-11-26T09:59:40Z")

</div>

That’s indeed weired… we’re using Mysql 5.0.19 and it’s the same behaviour as you describe. That also happens on 5.0.22.

If you do the same query using like instead of =,

… where u\_username like 'carpi ’

it doesn’t happen. I don’t know if that is expected behaviour by ANSI standard or mysql.

Greetings  
Christian

UPDATE: Guess its expected behaviour by ANSI-Standard. While looking in [bugs.mysql.com](http://bugs.mysql.com) I’ve found the following bug. At the end you can see a comment in the mysql source code, that says they ‘have’ to do it. )

[URL][MySQL Bugs: #14637: trim trailing spaces processes data only byte wise](http://bugs.mysql.com/bug.php?id=14637%5B/URL%5D)

---

<div class="post-metadata">

**Author:** ![Peter](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/peter/32/2_2.png) [@Peter](https://forums.percona.com/u/Peter)\
**Post date:** [November 27, 2006, 9:32am UTC](https://forums.percona.com/t/normal-for-mysql-to-strip-trailing-spaces/133/3 "2006-11-27T09:32:54Z")

</div>

Yeah,

This is far from being obvious but this is how it is designed.

See: [URL][MySQL](http://www.mysql.org/doc/refman/5.1/en/char.html%5B/URL%5D)
