<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="string-literals">
      </a>
      11.1.1 String Literals
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045220637808">
  </a>
  <a class="indexterm" name="idm46045220636320">
  </a>
  <a class="indexterm" name="idm46045220635248">
  </a>
  <a class="indexterm" name="idm46045220633760">
  </a>
  <a class="indexterm" name="idm46045220632272">
  </a>
  <a class="indexterm" name="idm46045220630784">
  </a>
  <p>
   A string is a sequence of bytes or characters, enclosed within
        either single quote (
   <code class="literal">
    '
   </code>
   ) or double quote
        (
   <code class="literal">
    "
   </code>
   ) characters. Examples:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29223045"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token string">'a string'</span>
<span class="token string">"another string"</span></code></pre>
  </div>
  <a class="indexterm" name="idm46045220626448">
  </a>
  <a class="indexterm" name="idm46045220625376">
  </a>
  <p>
   Quoted strings placed next to each other are concatenated to a
        single string. The following lines are equivalent:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa62397403"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token string">'a string'</span>
<span class="token string">'a'</span> <span class="token string">' '</span> <span class="token string">'string'</span></code></pre>
  </div>
  <p>
   If the
   <a class="link" href="sql-mode.html#sqlmode_ansi_quotes">
    <code class="literal">
     ANSI_QUOTES
    </code>
   </a>
   SQL mode is
        enabled, string literals can be quoted only within single
        quotation marks because a string quoted within double quotation
        marks is interpreted as an identifier.
  </p>
  <p>
   A
   <span class="firstterm">
    binary string
   </span>
   is a
        string of bytes. Every binary string has a character set and
        collation named
   <code class="literal">
    binary
   </code>
   . A
   <span class="firstterm">
    nonbinary string
   </span>
   is a
        string of characters. It has a character set other than
   <code class="literal">
    binary
   </code>
   and a collation that is compatible
        with the character set.
  </p>
  <p>
   For both types of strings, comparisons are based on the numeric
        values of the string unit. For binary strings, the unit is the
        byte; comparisons use numeric byte values. For nonbinary
        strings, the unit is the character and some character sets
        support multibyte characters; comparisons use numeric character
        code values. Character code ordering is a function of the string
        collation. (For more information, see
   <a class="xref" href="charset-binary-collations.html" title="12.8.5 The binary Collation Compared to _bin Collations">
    Section 12.8.5, “The binary Collation Compared to _bin Collations”
   </a>
   .)
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Within the
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client, binary strings
          display using hexadecimal notation, depending on the value of
          the
    <a class="link" href="mysql-command-options.html#option_mysql_binary-as-hex">
     <code class="option">
      --binary-as-hex
     </code>
    </a>
    . For more
          information about that option, see
    <a class="xref" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     Section 6.5.1, “mysql — The MySQL Command-Line Client”
    </a>
    .
   </p>
  </div>
  <p>
   A character string literal may have an optional character set
        introducer and
   <code class="literal">
    COLLATE
   </code>
   clause, to designate
        it as a string that uses a particular character set and
        collation:
  </p>
  <a class="indexterm" name="idm46045220610144">
  </a>
  <a class="indexterm" name="idm46045220608656">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa52601044"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token punctuation">[</span>_<em class="replaceable">charset_name</em><span class="token punctuation">]</span><span class="token string">'<em class="replaceable">string</em>'</span> <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   Examples:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60348851"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> _latin1<span class="token string">'<em class="replaceable">string</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> _binary<span class="token string">'<em class="replaceable">string</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> _utf8mb4<span class="token string">'<em class="replaceable">string</em>'</span> <span class="token keyword">COLLATE</span> utf8mb4_danish_ci<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   You can use
   <code class="literal">
    N'
    <em class="replaceable">
     <code>
      literal
     </code>
    </em>
    '
   </code>
   (or
   <code class="literal">
    n'
    <em class="replaceable">
     <code>
      literal
     </code>
    </em>
    '
   </code>
   ) to
        create a string in the national character set. These statements
        are equivalent:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84577320"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> N<span class="token string">'some text'</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> n<span class="token string">'some text'</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> _utf8<span class="token string">'some text'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For information about these forms of string syntax, see
   <a class="xref" href="charset-national.html" title="12.3.7 The National Character Set">
    Section 12.3.7, “The National Character Set”
   </a>
   , and
   <a class="xref" href="charset-introducer.html" title="12.3.8 Character Set Introducers">
    Section 12.3.8, “Character Set Introducers”
   </a>
   .
  </p>
  <p>
   Within a string, certain sequences have special meaning unless
        the
   <a class="link" href="sql-mode.html#sqlmode_no_backslash_escapes">
    <code class="literal">
     NO_BACKSLASH_ESCAPES
    </code>
   </a>
   SQL
        mode is enabled. Each of these sequences begins with a backslash
        (
   <code class="literal">
    \
   </code>
   ), known as the
   <span class="emphasis">
    <em>
     escape
        character
    </em>
   </span>
   . MySQL recognizes the escape sequences
        shown in
   <a class="xref" href="string-literals.html#character-escape-sequences" title="Table 11.1 Special Character Escape Sequences">
    Table 11.1, “Special Character Escape Sequences”
   </a>
   . For all
        other escape sequences, backslash is ignored. That is, the
        escaped character is interpreted as if it was not escaped. For
        example,
   <code class="literal">
    \x
   </code>
   is just
   <code class="literal">
    x
   </code>
   .
        These sequences are case-sensitive. For example,
   <code class="literal">
    \b
   </code>
   is interpreted as a backspace, but
   <code class="literal">
    \B
   </code>
   is interpreted as
   <code class="literal">
    B
   </code>
   .
        Escape processing is done according to the character set
        indicated by the
   <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
    <code class="literal">
     character_set_connection
    </code>
   </a>
   system
        variable. This is true even for strings that are preceded by an
        introducer that indicates a different character set, as
        discussed in
   <a class="xref" href="charset-literal.html" title="12.3.6 Character String Literal Character Set and Collation">
    Section 12.3.6, “Character String Literal Character Set and Collation”
   </a>
   .
  </p>
  <div class="table">
   <a name="character-escape-sequences">
   </a>
   <p class="title">
    <b>
     Table 11.1 Special Character Escape Sequences
    </b>
   </p>
   <div class="table-contents">
    <table summary="Escape sequences and the characters they represent.">
     <colgroup>
      <col style="width: 15%"/>
      <col style="width: 85%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Escape Sequence
       </th>
       <th>
        Character Represented by Sequence
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <code class="literal">
         \0
        </code>
        <a class="indexterm" name="idm46045220579648">
        </a>
        <a class="indexterm" name="idm46045220578704">
        </a>
       </td>
       <td>
        An ASCII NUL (
        <code class="literal">
         X'00'
        </code>
        ) character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \'
        </code>
        <a class="indexterm" name="idm46045220574528">
        </a>
        <a class="indexterm" name="idm46045220573584">
        </a>
       </td>
       <td>
        A single quote (
        <code class="literal">
         '
        </code>
        ) character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \"
        </code>
        <a class="indexterm" name="idm46045220569408">
        </a>
        <a class="indexterm" name="idm46045220568464">
        </a>
       </td>
       <td>
        A double quote (
        <code class="literal">
         "
        </code>
        ) character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \b
        </code>
        <a class="indexterm" name="idm46045220564288">
        </a>
        <a class="indexterm" name="idm46045220563344">
        </a>
       </td>
       <td>
        A backspace character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \n
        </code>
        <a class="indexterm" name="idm46045220559856">
        </a>
        <a class="indexterm" name="idm46045220558912">
        </a>
        <a class="indexterm" name="idm46045220557968">
        </a>
        <a class="indexterm" name="idm46045220557024">
        </a>
       </td>
       <td>
        A newline (linefeed) character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \r
        </code>
        <a class="indexterm" name="idm46045220553520">
        </a>
        <a class="indexterm" name="idm46045220552576">
        </a>
        <a class="indexterm" name="idm46045220551632">
        </a>
       </td>
       <td>
        A carriage return character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \t
        </code>
        <a class="indexterm" name="idm46045220548128">
        </a>
        <a class="indexterm" name="idm46045220547184">
        </a>
       </td>
       <td>
        A tab character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \Z
        </code>
        <a class="indexterm" name="idm46045220543696">
        </a>
        <a class="indexterm" name="idm46045220542752">
        </a>
       </td>
       <td>
        ASCII 26 (Control+Z); see note following the table
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \\
        </code>
        <a class="indexterm" name="idm46045220539232">
        </a>
        <a class="indexterm" name="idm46045220538288">
        </a>
       </td>
       <td>
        A backslash (
        <code class="literal">
         \
        </code>
        ) character
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \%
        </code>
        <a class="indexterm" name="idm46045220534112">
        </a>
        <a class="indexterm" name="idm46045220533168">
        </a>
       </td>
       <td>
        A
        <code class="literal">
         %
        </code>
        character; see note following the table
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         \_
        </code>
        <a class="indexterm" name="idm46045220528944">
        </a>
        <a class="indexterm" name="idm46045220528000">
        </a>
       </td>
       <td>
        A
        <code class="literal">
         _
        </code>
        character; see note following the table
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <div class="table-contents">
    <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 739px;">
     <thead>
      <tr>
       <th style="width: 110.688px;">
        Escape Sequence
       </th>
       <th style="width: 627.312px;">
        Character Represented by Sequence
       </th>
      </tr>
     </thead>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   The ASCII 26 character can be encoded as
   <code class="literal">
    \Z
   </code>
   to enable you to work around the problem that ASCII 26 stands
        for END-OF-FILE on Windows. ASCII 26 within a file causes
        problems if you try to use
   <code class="literal">
    mysql
    <em class="replaceable">
     <code>
      db_name
     </code>
    </em>
    &lt;
    <em class="replaceable">
     <code>
      file_name
     </code>
    </em>
   </code>
   .
  </p>
  <p>
   The
   <code class="literal">
    \%
   </code>
   and
   <code class="literal">
    \_
   </code>
   sequences
        are used to search for literal instances of
   <code class="literal">
    %
   </code>
   and
   <code class="literal">
    _
   </code>
   in pattern-matching contexts where they
        would otherwise be interpreted as wildcard characters. See the
        description of the
   <a class="link" href="string-comparison-functions.html#operator_like">
    <code class="literal">
     LIKE
    </code>
   </a>
   operator in
   <a class="xref" href="string-comparison-functions.html" title="14.8.1 String Comparison Functions and Operators">
    Section 14.8.1, “String Comparison Functions and Operators”
   </a>
   . If you use
   <code class="literal">
    \%
   </code>
   or
   <code class="literal">
    \_
   </code>
   outside of
        pattern-matching contexts, they evaluate to the strings
   <code class="literal">
    \%
   </code>
   and
   <code class="literal">
    \_
   </code>
   , not to
   <code class="literal">
    %
   </code>
   and
   <code class="literal">
    _
   </code>
   .
  </p>
  <a class="indexterm" name="idm46045220512672">
  </a>
  <p>
   There are several ways to include quote characters within a
        string:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A
      <code class="literal">
       '
      </code>
      inside a string quoted with
      <code class="literal">
       '
      </code>
      may be written as
      <code class="literal">
       ''
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      A
      <code class="literal">
       "
      </code>
      inside a string quoted with
      <code class="literal">
       "
      </code>
      may be written as
      <code class="literal">
       ""
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      Precede the quote character by an escape character
            (
      <code class="literal">
       \
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      A
      <code class="literal">
       '
      </code>
      inside a string quoted with
      <code class="literal">
       "
      </code>
      needs no special treatment and need not
            be doubled or escaped. In the same way,
      <code class="literal">
       "
      </code>
      inside a string quoted with
      <code class="literal">
       '
      </code>
      needs no
            special treatment.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The following
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   statements
        demonstrate how quoting and escaping work:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72181678"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'hello'</span><span class="token punctuation">,</span> <span class="token string">'"hello"'</span><span class="token punctuation">,</span> <span class="token string">'""hello""'</span><span class="token punctuation">,</span> <span class="token string">'hel'</span><span class="token string">'lo'</span><span class="token punctuation">,</span> <span class="token string">'\'hello'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> hello <span class="token punctuation">|</span> "hello" <span class="token punctuation">|</span> ""hello"" <span class="token punctuation">|</span> hel'lo <span class="token punctuation">|</span> 'hello <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">"hello"</span><span class="token punctuation">,</span> <span class="token string">"'hello'"</span><span class="token punctuation">,</span> <span class="token string">"''hello''"</span><span class="token punctuation">,</span> <span class="token string">"hel"</span><span class="token string">"lo"</span><span class="token punctuation">,</span> <span class="token string">"\"hello"</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> hello <span class="token punctuation">|</span> 'hello' <span class="token punctuation">|</span> ''hello'' <span class="token punctuation">|</span> hel"lo <span class="token punctuation">|</span> "hello <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'This\nIs\nFour\nLines'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token operator">|</span> This
<span class="token operator">Is</span>
Four
<span class="token keyword">Lines</span> <span class="token operator">|</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token string">'disappearing\ backslash'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> disappearing backslash <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <a class="indexterm" name="idm46045220492800">
  </a>
  <p>
   To insert binary data into a string column (such as a
   <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
    <code class="literal">
     BLOB
    </code>
   </a>
   column), you should
        represent certain characters by escape sequences. Backslash
        (
   <code class="literal">
    \
   </code>
   ) and the quote character used to quote the
        string must be escaped. In certain client environments, it may
        also be necessary to escape
   <code class="literal">
    NUL
   </code>
   or Control+Z.
        The
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client truncates quoted strings
        containing
   <code class="literal">
    NUL
   </code>
   characters if they are not
        escaped, and Control+Z may be taken for END-OF-FILE on Windows
        if not escaped. For the escape sequences that represent each of
        these characters, see
   <a class="xref" href="string-literals.html#character-escape-sequences" title="Table 11.1 Special Character Escape Sequences">
    Table 11.1, “Special Character Escape Sequences”
   </a>
   .
  </p>
  <a class="indexterm" name="idm46045220485536">
  </a>
  <a class="indexterm" name="idm46045220484464">
  </a>
  <a class="indexterm" name="idm46045220482976">
  </a>
  <a class="indexterm" name="idm46045220481936">
  </a>
  <a class="indexterm" name="idm46045220480864">
  </a>
  <p>
   When writing application programs, any string that might contain
        any of these special characters must be properly escaped before
        the string is used as a data value in an SQL statement that is
        sent to the MySQL server. You can do this in two ways:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Process the string with a function that escapes the special
            characters. In a C program, you can use the
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-escape-string-quote.html" target="_top">
       <code class="literal">
        mysql_real_escape_string_quote()
       </code>
      </a>
      C API function to escape characters. See
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-escape-string-quote.html" target="_top">
       mysql_real_escape_string_quote()
      </a>
      . Within SQL
            statements that construct other SQL statements, you can use
            the
      <a class="link" href="string-functions.html#function_quote">
       <code class="literal">
        QUOTE()
       </code>
      </a>
      function. The
            Perl DBI interface provides a
      <code class="literal">
       quote
      </code>
      method to convert special characters to the proper escape
            sequences. See
      <a class="xref" href="apis-perl.html" title="31.9 MySQL Perl API">
       Section 31.9, “MySQL Perl API”
      </a>
      . Other language
            interfaces may provide a similar capability.
     </p>
    </li>
    <li class="listitem">
     <p>
      As an alternative to explicitly escaping special characters,
            many MySQL APIs provide a placeholder capability that
            enables you to insert special markers into a statement
            string, and then bind data values to them when you issue the
            statement. In this case, the API takes care of escaping
            special characters in the values for you.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
