MySQL Shell 9.0

6.13 Executing SQL on Topologies

The execute() function enables you to execute SQL queries and statements across all, or a selection of, the members of a topology.

Important

This function must be used with care. For example, altering the value of a required system variable on multiple members could leave your managed topology in an unusable state. Also, this function acquires AdminAPI locks, which means some AdminAPI commands, such as addInstance() are blocked while this function is running.

      topologyType.execute(cmd, instances, options)
    

The result is returned as JSON.

A simple SQL statement, SHOW DATABASES, executed on the Cluster primary, returns the following:

cluster.execute("show databases;", "primary")
Statement will be executed at: 'IPAddress:4100'

Executing statement on instances (press Ctrl+C to cancel)... finished.
[
    {
        "executionTime": 0.0006606,
        "instance": {
            "address": "IPAddress:4100",
            "version": "9.0.0"
        },
        "output": [
            {
                "columnNames": [
                    "Database"
                ],
                "rows": [
                    [
                        "information_schema"
                    ],
                    [
                        "mysql"
                    ],
                    [
                        "mysql_innodb_cluster_metadata"
                    ],
                    [
                        "performance_schema"
                    ],
                    [
                        "sys"
                    ]
                ]
            }
        ]
    }
]