Skip to content
Domas Mituzas edited this page Apr 12, 2020 · 10 revisions

pmysql allows you to query multiple servers at once

Table of Contents

Input

standard way to use it is:

 echo hosts | pmysql "query"

You always need to specify a default query, even if you later will be overriding it in the input.

It supports extended input modes, where input is tab-separated and db lists are comma-separated:

 host:port
 host:port query
 host:port dblist query

It also allows to tag output of each query by specifying tags:

 host:port tag dblist query

Or with -x:

 host:port tag query

You can construct pipelines with it:

 list-servers | pmysql "
    SELECT CONCAT ('KILL ',id) 
    FROM information_Schema.processlist
    WHERE user='baduser'
    " | pmysql -

You can override port numbers with an increment (e.g. -i 10 will connect to 3316).

It also supports iterating over multiple databases

Output

It also supports multiple output modes:

  • By default it will output tab-separated fields, with fields escaped
  • -G will output line-per-field
  • -D will prepend each field with field name
  • -E will turn off escaping of special characters
  • -z will also print timing information per each query

Performance

Default execution mode uses a thread pool of workers, all of them running things in parallel. There is also super-fast mode (-Z) which uses async client in https://github.com/facebook/mysql-5.6

There're multiple parameters that change behavior:

  • -c enables protocol compression
  • -R sets read timeout
  • -T sets write timeout
  • -t sets up number of in-flight queries (threads in regular worker)

Security

pmysql reads standard configuration from ~/.my.cnf, but username/password and SSL settings can be overridden in command line too.

Clone this wiki locally