<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="apis-perl">
      </a>
      31.9 MySQL Perl API
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045060342208">
  </a>
  <a class="indexterm" name="idm46045060340752">
  </a>
  <a class="indexterm" name="idm46045060339680">
  </a>
  <a class="indexterm" name="idm46045060338608">
  </a>
  <p>
   The Perl
   <code class="literal">
    DBI
   </code>
   module provides a generic interface
    for database access. You can write a DBI script that works with many
    different database engines without change. To use DBI with MySQL,
    install the following:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      The
      <code class="literal">
       DBI
      </code>
      module.
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <code class="literal">
       DBD::mysql
      </code>
      module. This is the DataBase
        Driver (DBD) module for Perl.
     </p>
    </li>
    <li class="listitem">
     <p>
      Optionally, the DBD module for any other type of database server
        you want to access.
     </p>
    </li>
   </ol>
  </div>
  <p>
   Perl DBI is the recommended Perl interface. It replaces an older
    interface called
   <code class="literal">
    mysqlperl
   </code>
   , which should be
    considered obsolete.
  </p>
  <p>
   These sections contain information about using Perl with MySQL and
    writing MySQL applications in Perl:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      For installation instructions for Perl DBI support, see
      <a class="xref" href="perl-support.html" title="2.10 Perl Installation Notes">
       Section 2.10, “Perl Installation Notes”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For an example of reading options from option files, see
      <a class="xref" href="multiple-server-clients.html" title="7.8.4 Using Client Programs in a Multiple-Server Environment">
       Section 7.8.4, “Using Client Programs in a Multiple-Server Environment”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For secure coding tips, see
      <a class="xref" href="security-guidelines.html" title="8.1.1 Security Guidelines">
       Section 8.1.1, “Security Guidelines”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For debugging tips, see
      <a class="xref" href="using-gdb-on-mysqld.html" title="7.9.1.4 Debugging mysqld under gdb">
       Section 7.9.1.4, “Debugging mysqld under gdb”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For some Perl-specific environment variables, see
      <a class="xref" href="environment-variables.html" title="6.9 Environment Variables">
       Section 6.9, “Environment Variables”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For considerations for running on macOS, see
      <a class="xref" href="macos-installation.html" title="2.4 Installing MySQL on macOS">
       Section 2.4, “Installing MySQL on macOS”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For ways to quote string literals, see
      <a class="xref" href="string-literals.html" title="11.1.1 String Literals">
       Section 11.1.1, “String Literals”
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   DBI information is available at the command line, online, or in
    printed form:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Once you have the
      <code class="literal">
       DBI
      </code>
      and
      <code class="literal">
       DBD::mysql
      </code>
      modules installed, you can get
        information about them at the command line with the
      <code class="literal">
       perldoc
      </code>
      command:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa77570387"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">perldoc</span> DBI
<span class="token prompt">$&gt; </span><span class="token command">perldoc</span> DBI<span class="token punctuation">:</span><span class="token punctuation">:</span>FAQ
<span class="token prompt">$&gt; </span><span class="token command">perldoc</span> DBD<span class="token punctuation">:</span><span class="token punctuation">:</span>mysql</code></pre>
     </div>
     <p>
      You can also use
      <code class="literal">
       pod2man
      </code>
      ,
      <code class="literal">
       pod2html
      </code>
      , and so on to translate this
        information into other formats.
     </p>
    </li>
    <li class="listitem">
     <p>
      For online information about Perl DBI, visit the DBI website,
      <a class="ulink" href="http://dbi.perl.org/" target="_blank">
       http://dbi.perl.org/
      </a>
      . That site hosts a general
        DBI mailing list.
     </p>
    </li>
    <li class="listitem">
     <p>
      For printed information, the official DBI book is
      <em class="citetitle">
       Programming the Perl DBI
      </em>
      (Alligator
        Descartes and Tim Bunce, O'Reilly &amp; Associates, 2000).
        Information about the book is available at the DBI website,
      <a class="ulink" href="http://dbi.perl.org/" target="_blank">
       http://dbi.perl.org/
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
