<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="mysql-shell-tutorial-python-shell">
      </a>
      22.4.1 MySQL Shell
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045127402928">
  </a>
  <p>
   This quick-start guide assumes a certain level of familiarity with
      MySQL Shell. The following section is a high level overview, see
      the MySQL Shell documentation for more information. MySQL Shell
      is a unified scripting interface to MySQL Server. It supports
      scripting in JavaScript and Python. JavaScript is the default
      processing mode.
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="mysql-shell-tutorial-python-shell-start">
       </a>
       Start MySQL Shell
      </h4>
     </div>
    </div>
   </div>
   <p>
    After you have installed and started MySQL server, connect
        MySQL Shell to the server instance. You need to know the
        address of the MySQL server instance you plan to connect to. To
        be able to use the instance as a Document Store, the server
        instance must have X Plugin installed and you should connect to
        the server using X Protocol. For example to connect to the
        instance
    <code class="literal">
     ds1.example.com
    </code>
    on the default
        X Protocol port of 33060 use the network string
    <code class="literal">
     <em class="replaceable">
      <code>
       user
      </code>
     </em>
     @ds1.example.com:33060
    </code>
    .
   </p>
   <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Tip
    </div>
    <p>
     If you connect to the instance using classic MySQL protocol, for
          example by using the default
     <a class="link" href="server-system-variables.html#sysvar_port">
      <code class="literal">
       port
      </code>
     </a>
     of 3306 instead of the
     <a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_port">
      <code class="literal">
       mysqlx_port
      </code>
     </a>
     , you
     <span class="emphasis">
      <em>
       cannot
      </em>
     </span>
     use the Document Store
          functionality shown in this tutorial. For example the
     <code class="literal">
      db
     </code>
     global object is not populated. To use
          the Document Store, always connect using X Protocol.
    </p>
   </div>
   <p>
    If MySQL Shell is not already running, open a terminal window
        and issue:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa7852031"><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">mysqlsh <em class="replaceable">user</em>@ds1<span class="token punctuation">.</span>example<span class="token punctuation">.</span>com<span class="token punctuation">:</span>33060/world_x</code></pre>
   </div>
   <p>
    Alternatively, if MySQL Shell is already running use the
    <code class="literal">
     \connect
    </code>
    command by issuing:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa25159583"><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-mysqlsh">\connect <em class="replaceable">user</em>@ds1<span class="token punctuation">.</span>example<span class="token punctuation">.</span>com<span class="token punctuation">:</span><span class="token number">33060</span><span class="token operator">/</span>world_x</code></pre>
   </div>
   <p>
    You need to specify the address of the MySQL server instance
        which you want to connect MySQL Shell to. For example in the
        previous example:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <em class="replaceable">
        <code>
         user
        </code>
       </em>
       represents the user name of
            your MySQL account.
      </p>
     </li>
     <li class="listitem">
      <p>
       <code class="literal">
        ds1.example.com
       </code>
       is the hostname of the
            server instance running MySQL. Replace this with the
            hostname of the MySQL server instance you are using as a
            Document Store.
      </p>
     </li>
     <li class="listitem">
      <p>
       The default schema for this session is
       <code class="literal">
        world_x
       </code>
       . For instructions on setting up
            the
       <code class="literal">
        world_x
       </code>
       schema, see
       <a class="xref" href="mysql-shell-tutorial-python-download.html" title="22.4.2 Download and Import world_x Database">
        Section 22.4.2, “Download and Import world_x Database”
       </a>
       .
      </p>
     </li>
    </ul>
   </div>
   <p>
    For more information, see
    <a class="xref" href="connecting-using-uri-or-key-value-pairs.html" title="6.2.5 Connecting to the Server Using URI-Like Strings or Key-Value Pairs">
     Section 6.2.5, “Connecting to the Server Using URI-Like Strings or Key-Value Pairs”
    </a>
    .
   </p>
   <p>
    Once MySQL Shell opens, the
    <code class="literal">
     mysql-js&gt;
    </code>
    prompt indicates that the active language for this session is
        JavaScript. To switch MySQL Shell to Python mode, use the
    <code class="literal">
     \py
    </code>
    command.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa30453219"><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-mysqlsh"><span class="token prompt">mysql-js&gt;</span> \py
Switching to Python mode<span class="token operator">...</span>
<span class="token prompt">mysql-py&gt;</span></code></pre>
   </div>
   <p>
    MySQL Shell supports input-line editing as follows:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <span class="keycap">
        <strong>
         left-arrow
        </strong>
       </span>
       and
       <span class="keycap">
        <strong>
         right-arrow
        </strong>
       </span>
       keys move horizontally within the current input line.
      </p>
     </li>
     <li class="listitem">
      <p>
       <span class="keycap">
        <strong>
         up-arrow
        </strong>
       </span>
       and
       <span class="keycap">
        <strong>
         down-arrow
        </strong>
       </span>
       keys move up and down through the set of previously entered
            lines.
      </p>
     </li>
     <li class="listitem">
      <p>
       <span class="keycap">
        <strong>
         Backspace
        </strong>
       </span>
       deletes the character before the
            cursor and typing new characters enters them at the cursor
            position.
      </p>
     </li>
     <li class="listitem">
      <p>
       <span class="keycap">
        <strong>
         Enter
        </strong>
       </span>
       sends the current input line to the
            server.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="mysql-shell-tutorial-python-shell-help">
       </a>
       Get Help for MySQL Shell
      </h4>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127364816">
   </a>
   <p>
    Type
    <span class="command">
     <strong>
      mysqlsh --help
     </strong>
    </span>
    at the prompt of your
        command interpreter for a list of command-line options.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa61160619"><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">mysqlsh <span class="token property">--help</span></code></pre>
   </div>
   <p>
    Type
    <code class="literal">
     \help
    </code>
    at the MySQL Shell prompt for a
        list of available commands and their descriptions.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa76179649"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> \help</code></pre>
   </div>
   <p>
    Type
    <code class="literal">
     \help
    </code>
    followed by a command name for
        detailed help about an individual MySQL Shell command. For
        example, to view help on the
    <code class="literal">
     \connect
    </code>
    command, issue:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa61762533"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> \help \connect</code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="mysql-shell-tutorial-python-shell-quit">
       </a>
       Quit MySQL Shell
      </h4>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045127352800">
   </a>
   <p>
    To quit MySQL Shell, issue the following command:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa24367469"><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-mysqlsh"><span class="token prompt">mysql-py&gt;</span> \quit</code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="idm46045127349104">
       </a>
       Related Information
      </h4>
     </div>
    </div>
   </div>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       See
       <a class="ulink" href="/doc/mysql-shell/8.4/en/mysql-shell-interactive-code-execution.html" target="_top">
        Interactive Code Execution
       </a>
       for an explanation of how interactive code execution works
            in MySQL Shell.
      </p>
     </li>
     <li class="listitem">
      <p>
       See
       <a class="ulink" href="/doc/mysql-shell/8.4/en/mysql-shell-getting-started.html" target="_top">
        Getting Started with MySQL Shell
       </a>
       to learn
            about session and connection alternatives.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
