MySQL Shell can connect to MySQL Server using both X Protocol and classic MySQL protocol. You can specify the MySQL server instance to which MySQL Shell connects in the following ways:
When you start MySQL Shell, using the command parameters. See Section 4.3.1, “Connecting using Individual Parameters”.
When MySQL Shell is running, using the
\connectcommand. See Section 3.1, “MySQL Shell Commands”.
These different ways of connecting to a MySQL server instance all support specifying the connection as follows:
Parameters specified with a URI-like string use a syntax such as
firstname.lastname@example.org:3306/main-schema. For the full syntax, see Connecting Using URI-Like Connection Strings.
Parameters specified with key-value pairs use a syntax such as
See Connecting to the Server Using URI-Like Strings or Key-Value Pairs for more information.
Regardless of how you choose to connect it is important to understand how passwords are handled by MySQL Shell. By default connections are assumed to require a password. The password (which has a maximum length of 128 characters) is requested at the login prompt, and can be stored using Section 4.4, “Pluggable Password Store”. If the user specified has a password-less account, which is insecure and not recommended, or if socket peer-credential authentication is in use (for example when using Unix socket connections), you must explicitly specify that no password is provided and the password prompt is not required. To do this, use one of the following methods:
If you are connecting using a URI-like connection string, place a
userin the string but do not specify a password after it.
If you are connecting using key-value pairs, provide an empty string using
If you do not specify parameters for a connection the following defaults are used:
userdefaults to the current system user name.
portdefaults to the X Plugin port 33060 when using an X Protocol connection, and port 3306 when using a classic MySQL protocol connection.
Instead of a TCP connection, you can connect using a Unix socket file or a Windows named pipe. For instructions, see Section 4.3.2, “Connecting using Unix Sockets and Windows Named Pipes”.
If the MySQL server instance supports encrypted connections, you can enable and configure the connection to use encryption. For instructions, see Section 4.3.3, “Using Encrypted Connections”.
If the connection to the server is lost, you can use the
\reconnect command, which makes MySQL Shell
try several reconnection attempts for the current global session
using the existing connection parameters. The
\reconnect command is specified without any
parameters or options. If those attempts are unsuccessful, you can
make a fresh connection using the
command and specifying the connection parameters.
To configure the connection timeout use the
connect-timeout connection parameter. The value
connect-timeout must be a non-negative
integer that defines a time frame in milliseconds. The timeout
default value is 10000 milliseconds, or 10 seconds. For example:
// Decrease the timeout to 2 seconds. mysql-js> \connect email@example.com?connect-timeout=2000 // Increase the timeout to 20 seconds mysql-js> \connect firstname.lastname@example.org?connect-timeout=20000
To disable the timeout set the value of
connect-timeout to 0, meaning that the client
waits until the underlying socket times out, which is platform
To enable compression for the connection, use the
compression connection parameter, for example:
mysql-js> \connect email@example.com?compression=true
When set to
true (or 1), this option enables
compression of all information sent between the client and the
server if possible. The default is no compression
false or 0). If you are connecting using
command parameters, the equivalent parameter is
Compression is available for MySQL Shell connections using
classic MySQL protocol only. You can set the
defaultCompress MySQL Shell configuration
option to enable compression for every global session. The
\status command shows whether or
not compression is enabled for the session.