LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

mysqlsh

mySQL Shell client

TLDR

Start MySQL Shell
$ mysqlsh
copy
Connect to server (prompts for the password)
$ mysqlsh -u [username] -h [hostname] -P [3306]
copy
Connect with URI
$ mysqlsh [user]@[host]:[3306]/[database]
copy
Execute a SQL statement and exit
$ mysqlsh --sql [user]@[host] -e "[SELECT VERSION()]"
copy
Start in JavaScript or Python mode
$ mysqlsh --js [user]@[host]
copy
$ mysqlsh --py [user]@[host]
copy
Run a script file
$ mysqlsh [user]@[host] -f [script.sql]
copy
Dump a whole instance with the parallel dump utility
$ mysqlsh [user]@[host] -- util dump-instance [/path/to/dump]
copy
Load a dump into a server
$ mysqlsh [user]@[host] -- util load-dump [/path/to/dump]
copy
Check a server before upgrading it
$ mysqlsh -- util check-for-server-upgrade [user]@[host]
copy

SYNOPSIS

mysqlsh [options] [URI]mysqlsh [options] [URI] -- object method [arguments]

DESCRIPTION

mysqlsh is MySQL Shell, an advanced client and code editor for MySQL. It works in SQL, JavaScript and Python modes, switchable at runtime with \sql, \js and \py.Beyond queries it bundles the AdminAPI (dba object) for deploying and managing InnoDB Cluster, ClusterSet and ReplicaSet, the X DevAPI for document store access, and the util object with parallel dump/load, upgrade checker and import utilities. Anything after -- on the command line is mapped to these API calls, which makes them scriptable.

PARAMETERS

URI

Connection string, e.g. user@host:port/schema or mysql://user@host.
-u, --user USER
Username.
-h, --host HOST
Hostname.
-P, --port PORT
TCP port (3306 classic protocol, 33060 X Protocol).
-S, --socket PATH
Unix socket file.
-p, --password[=PASS]
Password; prompts if no value is given.
-D, --schema NAME
Default schema.
--sql, --js, --py
Start in SQL, JavaScript or Python mode.
--sqlc
SQL mode using the classic MySQL protocol.
--mysql, -mc / --mysqlx, -mx
Force a classic or X Protocol session.
-e, --execute CODE
Execute code in the active language and quit.
-f, --file FILE
Process a file in batch mode.
--json[=pretty|raw]
Print output as JSON.
--result-format FORMAT
Output format: table, tabbed, vertical, json, ndjson, json/raw.
--ssl-mode MODE
TLS requirement: DISABLED, PREFERRED, REQUIRED, VERIFYCA, VERIFYIDENTITY.
--log-level LEVEL
Logging level (1 to 8 or none, internal, error, warning, info, debug...).
--cluster, --replicaset
Ensure the connection target is part of an InnoDB Cluster or ReplicaSet.
--help
Display help information.

CAVEATS

MySQL Shell is versioned together with MySQL Server; use a Shell release equal to or newer than the servers it manages. The classic mysql client remains separate. Credentials may be stored in a secret store; see --save-passwords.

HISTORY

MySQL Shell was introduced in 2016 alongside the MySQL 5.7 Document Store and X Protocol, and became the recommended administration client with MySQL 8.0.

SEE ALSO

mysql(1), mysqladmin(1), mysqldump(1), mycli(1)

RESOURCES

Copied to clipboard
Kai