Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.9Mb
PDF (A4) - 38.0Mb
PDF (RPM) - 37.3Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.3Mb
HTML Download (RPM) - 8.9Mb
Man Pages (TGZ) - 216.8Kb
Man Pages (Zip) - 329.5Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  MySQL Shell Commands

18.4.1 MySQL Shell Commands

MySQL Shell provides commands which enable you to modify the execution environment of the code editor, for example to configure the active programming language or a MySQL Server connection. The following table lists the commands that are available regardless of the currently selected language. As commands need to be available independent of the execution mode, they start with an escape sequence, the \ character.

CommandAlias/ShortcutDescription

\help

\h or \?

Prints help about MySQL Shell commands.

\quit

\q or \exit

Exit MySQL Shell.

\

 

In SQL mode, begin multiple-line mode. Code is cached and executed when an empty line is entered.

\status

 

Show the current MySQL Shell status.

\js

 

Switch execution mode to JavaScript.

\py

 

Switch execution mode to Python.

\sql

 

Switch execution mode to SQL.

\connect

\c

Connect to a MySQL Server with a URI using an XSession (X Protocol).

\connect_node

\cn

(Removed in version 1.0.4, use \connect -n) Connect to a MySQL Server with a URI using a Node session.

\connect_classic

\cc

(Removed in version 1.0.4, use \connect -c) Connect to a MySQL Server with a URI using a Classic session (MySQL Protocol).

\use

 

Specify the schema to use.

\source

\.

Execute a script file using the active language.

\warnings

\W

Show any warnings generated by a statement.

\nowarnings

\w

Do not show any warnings generated by a statement.

\lsconn

\lsc

Print the connection data for the stored sessions.

\saveconn

\savec

Save connection data of a session, optionaly use -f to force overwriting an existing connection.

\addconn

\addc

(Removed in version 1.0.4, see \saveconn) Store the connection data of a session.

\rmconn

 

Removes a stored session.

\chconn

 

(Removed in version 1.0.4, see \saveconn) Updates a stored session.

Help Command

The \help command can be used with or without parameters. When used without parameters a general help is printed including information about:

  • Available commands.

  • Available commands for the active mode.

When used with a parameter, the parameter must be a valid command. If that is the case, help for that specific command is printed including:

  • Description

  • Supported aliases if any

  • Additional help if any

For example:

\help connect

If the parameter is not a valid command, the general help is printed.

Connect Command

The \connect command is used to connect to a MySQL Server using an URI. This command creates an X Protocol connection by default.

For example:

\connect root@localhost:3306

If a password is required you are prompted for it.

Use the -n option to create a Node session, using the X Protocol to connect to a single server. For example:

\connect -n root@localhost:3306

Use the -c option to create a Classic session, enabling you to use the MySQL Protocol to issue SQL commands directly on a server. For example:

\connect -c root@localhost:3306

Source Command

The \source command is used to execute code from a script at a given path. For example:

\source /tmp/mydata.sql

It can be used to execute either SQL, JavaScript or Python code. The code in the file is executed using the active language, so to process SQL code the MySQL Shell must be in SQL mode.

Warning

As the code is executed using the active language, executing a script in a different language than the currently selected execution mode language could lead to unexpected results.

Use Command

The \use command enables you to choose which schema is active, for example:

\use schema_name

The \use command requires a global development session to be active. If the global development session is an XSession then the \use command only sets db to the object representing the schema_name but does not set a current schema on the database. If the global development session is one of NodeSession or ClassicSession the \use command sets the current schema to the specified schema_name and updates the db variable to the object that represents the selected schema.


User Comments
Sign Up Login You must be logged in to post a comment.