<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="charset-general">
      </a>
      12.1 Character Sets and Collations in General
     </h2>
    </div>
   </div>
  </div>
  <p>
   A
   <span class="firstterm">
    character set
   </span>
   is a set of
      symbols and encodings. A
   <span class="firstterm">
    collation
   </span>
   is a set of rules
      for comparing characters in a character set. Let's make the
      distinction clear with an example of an imaginary character set.
  </p>
  <p>
   Suppose that we have an alphabet with four letters:
   <code class="literal">
    A
   </code>
   ,
   <code class="literal">
    B
   </code>
   ,
   <code class="literal">
    a
   </code>
   ,
   <code class="literal">
    b
   </code>
   . We give each letter a number:
   <code class="literal">
    A
   </code>
   = 0,
   <code class="literal">
    B
   </code>
   = 1,
   <code class="literal">
    a
   </code>
   = 2,
   <code class="literal">
    b
   </code>
   = 3. The letter
   <code class="literal">
    A
   </code>
   is a symbol, the number 0 is the
   <span class="emphasis">
    <em>
     encoding
    </em>
   </span>
   for
   <code class="literal">
    A
   </code>
   , and the
      combination of all four letters and their encodings is a
   <span class="emphasis">
    <em>
     character set
    </em>
   </span>
   .
  </p>
  <p>
   Suppose that we want to compare two string values,
   <code class="literal">
    A
   </code>
   and
   <code class="literal">
    B
   </code>
   . The simplest way to
      do this is to look at the encodings: 0 for
   <code class="literal">
    A
   </code>
   and 1 for
   <code class="literal">
    B
   </code>
   . Because 0 is less than 1, we say
   <code class="literal">
    A
   </code>
   is less than
   <code class="literal">
    B
   </code>
   . What we've
      just done is apply a collation to our character set. The collation
      is a set of rules (only one rule in this case):
   <span class="quote">
    “
    <span class="quote">
     compare the
      encodings.
    </span>
    ”
   </span>
   We call this simplest of all possible
      collations a
   <span class="firstterm">
    binary
   </span>
   collation.
  </p>
  <p>
   But what if we want to say that the lowercase and uppercase
      letters are equivalent? Then we would have at least two rules: (1)
      treat the lowercase letters
   <code class="literal">
    a
   </code>
   and
   <code class="literal">
    b
   </code>
   as equivalent to
   <code class="literal">
    A
   </code>
   and
   <code class="literal">
    B
   </code>
   ; (2) then compare the encodings. We call this
      a
   <span class="firstterm">
    case-insensitive
   </span>
   collation. It is a little more complex than a binary collation.
  </p>
  <p>
   In real life, most character sets have many characters: not just
   <code class="literal">
    A
   </code>
   and
   <code class="literal">
    B
   </code>
   but whole alphabets,
      sometimes multiple alphabets or eastern writing systems with
      thousands of characters, along with many special symbols and
      punctuation marks. Also in real life, most collations have many
      rules, not just for whether to distinguish lettercase, but also
      for whether to distinguish accents (an
   <span class="quote">
    “
    <span class="quote">
     accent
    </span>
    ”
   </span>
   is a
      mark attached to a character as in German
   <code class="literal">
    Ö
   </code>
   ),
      and for multiple-character mappings (such as the rule that
   <code class="literal">
    Ö
   </code>
   =
   <code class="literal">
    OE
   </code>
   in one of the two
      German collations).
  </p>
  <p>
   MySQL can do these things for you:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Store strings using a variety of character sets.
     </p>
    </li>
    <li class="listitem">
     <p>
      Compare strings using a variety of collations.
     </p>
    </li>
    <li class="listitem">
     <p>
      Mix strings with different character sets or collations in the
          same server, the same database, or even the same table.
     </p>
    </li>
    <li class="listitem">
     <p>
      Enable specification of character set and collation at any
          level.
     </p>
    </li>
   </ul>
  </div>
  <p>
   To use these features effectively, you must know what character
      sets and collations are available, how to change the defaults, and
      how they affect the behavior of string operators and functions.
  </p>
 </div>
 <br/>
</div>
