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


  memsqlctl query [flags]

  -h, --help                   help for query
      --host string            the cluster-addressable hostname for the node
      --memsql-id string       the MemSQL ID of the node to query
  -p, --password STRING        the SQL password for connecting to MemSQL
      --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 30 seconds (default 1m0s)
  -e, --sql string             the SQL query to run
      --user string            the SQL user for connecting to MemSQL

Global Flags:
  -c, --config FILE_PATH                     Path to the memsqctl config file
      --default-install-dir DIRECTORY_PATH   Path to the default install directory
  -j, --json                                 Print output in JSON format
      --node-metadata-file FILE_PATH         Path to the node metadata file
      --parallelism int                      Maximum amount of operations to be run in parallel
      --ssl-ca FILE_PATH                     Path to the CA certificate file in PEM format to authenticate the MemSQL server certificate
      --timeout duration                     Maximum time for operation to complete (e.g., 30s, 10m, 1.5h)
  -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


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


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": [
  "rows": [
      "Database": "cluster"
      "Database": "information_schema"
      "Database": "memsql"
Was this article useful?