Outdated Version

You are viewing an older version of this section. View current production version.

query

Info

MemSQL Helios does not support this command.

A convenience wrapper for executing arbitrary SQL queries on a node on this host.

Usage

A convenience wrapper for executing arbitrary SQL queries on a node on this host

Usage:
  memsqlctl query [flags]

Flags:
  -h, --help                   Help for query
      --host string            The cluster-addressable hostname for the node
      --memsql-id string       The node ID of the node to query
  -p, --password STRING        The database user's password
      --port PORT              The cluster-addressable port for the node
      --row-timeout duration   Maximum time to wait for each row in the result (e.g., 30s, 10m, 1.5h); defaults to 1 minute (default 1m0s)
  -e, --sql string             The SQL query to run
      --user string            The database user

Global Flags:
  -c, --config FILE_PATH                     Path to the memsqctl config file
      --default-install-dir DIRECTORY_PATH   Path to the default install directory
      --insecure-ssl                         Fall back to insecure SSL connections to local SingleStoreDB nodes if memsqlctl is unable to otherwise establish a connection (ADVANCED)
  -j, --json                                 Print output in JSON format
      --node-metadata-file FILE_PATH         Path to the node metadata file
      --parallelism POSITIVE_INTEGER         Maximum amount of operations to be run in parallel
      --ssl-ca FILE_PATH                     The path to the CA certificate file (in PEM format) to authenticate the database certificate
      --timeout duration                     Maximum time for operation to complete (e.g., 30s, 10m, 1.5h)
      --verbose-json                         Print output in JSON format, include some warnings and user messages
  -v, --verbosity count                      Increase logging verbosity
  -y, --yes                                  Enable non-interactive mode and assume the user would like to move forward with the proposed actions by default

Remarks

This command is interactive unless you use either the --yes or --json flags to override interactive behavior.

The memsqlctl query command is equivalent to the sdb-admin query command.

Output

The following shows how to use the query command to run SHOW DATABASES against the master aggregator on the local host machine.

$ sudo memsqlctl query --sql "SHOW DATABASES"
+-------+------------+--------+------+---------------+---------+
| Index | MemSQL ID  |  Role  | Port | Process State | Version |
+-------+------------+--------+------+---------------+---------+
| 1     | 29EB592436 | Master | 3306 | Running       | 6.5.14  |
| 2     | 035F453938 | Leaf   | 3307 | Running       | 6.5.14  |
+-------+------------+--------+------+---------------+---------+
Select an option: 1
+--------------------+
|      Database      |
+--------------------+
| cluster            |
| information_schema |
| memsql             |
+--------------------+

Another example executes the same query on the master aggregator from its local host machine without specifying the memsql-id of the master aggregator node and printing the output in JSON format.

$ sudo memsqlctl list-nodes -q -r master | xargs -I % sudo memsqlctl query --sql "SHOW DATABASES" --memsql-id % --json
{
  "columns": [
    "Database"
  ],
  "rows": [
    {
      "Database": "cluster"
    },
    {
      "Database": "information_schema"
    },
    {
      "Database": "memsql"
    }
  ]
}