Unix Technical Forum

Is "Collation" in MySQL useful?

This is a discussion on Is "Collation" in MySQL useful? within the MySQL forums, part of the Database Server Software category; --> Hi, I found that even this settings of my MYSQL is set to "latin1_swedish_ci", I can still insert and ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:53 AM
howachen@gmail.com
 
Posts: n/a
Default Is "Collation" in MySQL useful?

Hi,

I found that even this settings of my MYSQL is set to
"latin1_swedish_ci", I can still insert and get back UTF-8 characters
in query. So what is reason?

Thanks...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:53 AM
howachen@gmail.com
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?


howachen@gmail.com 寫道:

> Hi,
>
> I found that even this settings of my MYSQL is set to
> "latin1_swedish_ci", I can still insert and get back UTF-8 characters
> in query. So what is reason?
>
> Thanks...


some interesting findings...

using PHP,

1. if the default character set of a table is set to
"latin1_swedish_ci", then query can return the correct utf8 data in
browser

2. if the default character set of a table is set to "utf-8", then
query CANNOT return the correct utf8 data in browser, i need to perform
another query before the real query, i.e. set names 'utf8'

so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
on every php connection? isn't ?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:53 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

howachen@gmail.com wrote:
> howachen@gmail.com 寫道:
>
>
>>Hi,
>>
>>I found that even this settings of my MYSQL is set to
>>"latin1_swedish_ci", I can still insert and get back UTF-8 characters
>>in query. So what is reason?
>>
>>Thanks...

>
>
> some interesting findings...
>
> using PHP,
>
> 1. if the default character set of a table is set to
> "latin1_swedish_ci", then query can return the correct utf8 data in
> browser
>
> 2. if the default character set of a table is set to "utf-8", then
> query CANNOT return the correct utf8 data in browser, i need to perform
> another query before the real query, i.e. set names 'utf8'
>
> so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
> on every php connection? isn't ?
>


MySQL, like all RDB's, just store bytes. You can put about anything into them.
But the collation has to do with the way it handles data in the ORDER clause
(collates).

See http://dev.mysql.com/doc/refman/5.1/...on-effect.html for an
example.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 08:53 AM
howachen@gmail.com
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?


Jerry Stuckle 寫道:

> howachen@gmail.com wrote:
> > howachen@gmail.com 寫道:
> >
> >
> >>Hi,
> >>
> >>I found that even this settings of my MYSQL is set to
> >>"latin1_swedish_ci", I can still insert and get back UTF-8 characters
> >>in query. So what is reason?
> >>
> >>Thanks...

> >
> >
> > some interesting findings...
> >
> > using PHP,
> >
> > 1. if the default character set of a table is set to
> > "latin1_swedish_ci", then query can return the correct utf8 data in
> > browser
> >
> > 2. if the default character set of a table is set to "utf-8", then
> > query CANNOT return the correct utf8 data in browser, i need to perform
> > another query before the real query, i.e. set names 'utf8'
> >
> > so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
> > on every php connection? isn't ?
> >

>
> MySQL, like all RDB's, just store bytes. You can put about anything intothem.
> But the collation has to do with the way it handles data in the ORDER clause
> (collates).
>
> See http://dev.mysql.com/doc/refman/5.1/...on-effect.html for an
> example.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================


so it that beside the "order clause" issue, there is no difference?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 08:53 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

howachen@gmail.com wrote:
> Jerry Stuckle 寫道:
>
>
>>howachen@gmail.com wrote:
>>
>>>howachen@gmail.com 寫道:
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>I found that even this settings of my MYSQL is set to
>>>>"latin1_swedish_ci", I can still insert and get back UTF-8 characters
>>>>in query. So what is reason?
>>>>
>>>>Thanks...
>>>
>>>
>>>some interesting findings...
>>>
>>>using PHP,
>>>
>>>1. if the default character set of a table is set to
>>>"latin1_swedish_ci", then query can return the correct utf8 data in
>>>browser
>>>
>>>2. if the default character set of a table is set to "utf-8", then
>>>query CANNOT return the correct utf8 data in browser, i need to perform
>>>another query before the real query, i.e. set names 'utf8'
>>>
>>>so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
>>>on every php connection? isn't ?
>>>

>>
>>MySQL, like all RDB's, just store bytes. You can put about anything into them.
>> But the collation has to do with the way it handles data in the ORDER clause
>>(collates).
>>
>>See http://dev.mysql.com/doc/refman/5.1/...on-effect.html for an
>>example.
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================

>
>
> so it that beside the "order clause" issue, there is no difference?
>


That's what the page says.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 08:53 AM
Gordon Burditt
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

>> > 1. if the default character set of a table is set to
>> > "latin1_swedish_ci", then query can return the correct utf8 data in
>> > browser
>> >
>> > 2. if the default character set of a table is set to "utf-8", then
>> > query CANNOT return the correct utf8 data in browser, i need to perform
>> > another query before the real query, i.e. set names 'utf8'
>> >
>> > so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
>> > on every php connection? isn't ?
>> >

>>
>> MySQL, like all RDB's, just store bytes. You can put about anything

>into them.
>> But the collation has to do with the way it handles data in the ORDER clause
>> (collates).
>>
>> See

>http://dev.mysql.com/doc/refman/5.1/...on-effect.html for
>an
>> example.
>>

....
>
>so it that beside the "order clause" issue, there is no difference?


I would assume that any operation that compares strings for other
than equality/inequality would be (at least potentially) be affected
by the collation, for instance
... WHERE a > b AND ...
with a and b being VARCHAR fields. ORDER BY is of course the main one.

Gordon L. Burditt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 08:53 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

Gordon Burditt wrote:
>>>>1. if the default character set of a table is set to
>>>>"latin1_swedish_ci", then query can return the correct utf8 data in
>>>>browser
>>>>
>>>>2. if the default character set of a table is set to "utf-8", then
>>>>query CANNOT return the correct utf8 data in browser, i need to perform
>>>>another query before the real query, i.e. set names 'utf8'
>>>>
>>>>so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
>>>>on every php connection? isn't ?
>>>>
>>>
>>>MySQL, like all RDB's, just store bytes. You can put about anything

>>
>>into them.
>>
>>> But the collation has to do with the way it handles data in the ORDER clause
>>>(collates).
>>>
>>>See

>>
>>http://dev.mysql.com/doc/refman/5.1/...on-effect.html for
>>an
>>
>>>example.
>>>

>
> ...
>
>>so it that beside the "order clause" issue, there is no difference?

>
>
> I would assume that any operation that compares strings for other
> than equality/inequality would be (at least potentially) be affected
> by the collation, for instance
> ... WHERE a > b AND ...
> with a and b being VARCHAR fields. ORDER BY is of course the main one.
>
> Gordon L. Burditt


Gordon,

I guess I wasn't clear. Yes, any comparisons like this are affected.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 08:53 AM
howachen@gmail.com
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?


Gordon Burditt 寫道:

> >> > 1. if the default character set of a table is set to
> >> > "latin1_swedish_ci", then query can return the correct utf8 data in
> >> > browser
> >> >
> >> > 2. if the default character set of a table is set to "utf-8", then
> >> > query CANNOT return the correct utf8 data in browser, i need to perform
> >> > another query before the real query, i.e. set names 'utf8'
> >> >
> >> > so why not use the "latin1_swedish_ci" ? no need to set names 'utf8'
> >> > on every php connection? isn't ?
> >> >
> >>
> >> MySQL, like all RDB's, just store bytes. You can put about anything

> >into them.
> >> But the collation has to do with the way it handles data in the ORDER clause
> >> (collates).
> >>
> >> See

> >http://dev.mysql.com/doc/refman/5.1/...on-effect.html for
> >an
> >> example.
> >>

> ...
> >
> >so it that beside the "order clause" issue, there is no difference?

>
> I would assume that any operation that compares strings for other
> than equality/inequality would be (at least potentially) be affected
> by the collation, for instance
> ... WHERE a > b AND ...
> with a and b being VARCHAR fields. ORDER BY is of course the main one.
>
> Gordon L. Burditt


however, comparsion/ordering on characters "might" not make sense on
other language such as Japanese or Chinese (in fact, event for english,
how many time your application would compare "apple" > "orange" ? i
doubt)

so, collation is only useful for western language i think. setting
collation to latin is okay for some languages.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 08:53 AM
=?UTF-8?B?UGhpbGlwcCBUw7Zsa2U=?=
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

howachen@gmail.com wrote:
>> [Collation]

>
> so it that beside the "order clause" issue, there is no difference?


UNIQUE keys also behave differently between a case-sensitive and a
case-insensitive Collation. "collation" and "Collation" can't be both in
a case-insensitive UNIQUE-Column, but in a case-sensitive one they could.

Cheers,
--
Philipp Tölke
PGP 0x96A1FE7A
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 08:53 AM
Axel Schwenke
 
Posts: n/a
Default Re: Is "Collation" in MySQL useful?

gordonb.0s4w1@burditt.org (Gordon Burditt) wrote:

>>so it that beside the "order clause" issue, there is no difference?

>
> I would assume that any operation that compares strings for other
> than equality/inequality would be (at least potentially) be affected
> by the collation, for instance
> ... WHERE a > b AND ...
> with a and b being VARCHAR fields. ORDER BY is of course the main one.


Collations even affect equality tests. Most collations (in MySQL) come
in two variants: *_ci = case insensitive and *_cs = case sensitive.

So SELECT 'Apple' = 'apple' may be true or false, depending on the
collation used.

Some western languages have quite surprising collation rules. I.e. the
(MySQL default) Swedish collation defines 'y' = ''. One of the German
collations defines 'a' = '', 'o' = '' and so on.

So setting the correct collation is mandatory. Even if you live in a
part of the world where collation rules are simple.


XL
--
Axel Schwenke, Senior Software Developer, MySQL AB

Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
MySQL User Forums: http://forums.mysql.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com