Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 0.5Mb
PDF (A4) - 0.5Mb
HTML Download (TGZ) - 102.8Kb
HTML Download (Zip) - 114.7Kb


MySQL Shell 8.0  /  ...  /  Creating the Session Global Object While Starting MySQL Shell

4.2.1 Creating the Session Global Object While Starting MySQL Shell

When you start MySQL Shell from the command line, you can specify connection parameters using separate command options for each value, such as the user name, host, and port. For instructions and examples to start MySQL Shell and connect to a MySQL Server instance in this way, see Section 4.3.1, “Connecting using Individual Parameters”. When you use this connection method, you can add one of these options to choose the type of session object to create at startup to be the session global object:

  • --mysqlx (--mx) creates a Session object, which connects to the MySQL Server instance using X Protocol.

  • --mysql (--mc) creates a ClassicSession object, which connects to the MySQL Server instance using MySQL protocol.

For example, this command starts MySQL Shell and establishes an X Protocol connection to a local MySQL Server instance listening at port 33060:

shell> mysqlsh --mysqlx -u user -h localhost -P 33060

If you are starting MySQL Shell in SQL mode, the --sqlx and --sqlc options include a choice of session object type, so you can specify one of these instead to make MySQL Shell use X Protocol or MySQL protocol for the connection. For a reference for all the mysqlsh command line options, see Section A.1, “mysqlsh — The MySQL Shell”.

As an alternative to specifying the connection parameters using individual options, you can specify them using a URI-like connection string. You can pass in this string when you start MySQL Shell from the command line, with or without using the optional --uri command option. When you use this connection method, you can include the scheme element at the start of the URI-like connection string to select the type of session object to create. mysqlx creates a Session object using X Protocol, or mysql creates a ClassicSession object using MySQL protocol. For example, either of these commands uses a URI-like connection string to start MySQL Shell and create a MySQL protocol connection to a local MySQL Server instance listening at port 3306:

shell> mysqlsh --uri mysql://user@localhost:3306
shell> mysqlsh mysql://user@localhost:3306

You can also specify the connection protocol as an option rather than as part of the URI-like connection string, for example:

shell> mysqlsh --mysql --uri user@localhost:3306

For instructions and examples to connect to a MySQL Server instance in this way, see Connecting to the Server Using URI-Like Strings or Key-Value Pairs.