Example #1
0
import time
from mysql.utilities import VERSION_FRM
from mysql.utilities.command.serverinfo import show_server_info
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.options import add_format_option
from mysql.utilities.common.options import add_verbosity

from mysql.utilities.exception import UtilError

# Constants
NAME = "MySQL Utilities - mysqlserverinfo "
DESCRIPTION = "mysqlserverinfo - show server information"
USAGE = "%prog --server=user:pass@host:port:socket --format=grid"

# Setup the command parser and setup server, help
parser = setup_common_options(os.path.basename(sys.argv[0]),
                              DESCRIPTION, USAGE, True)

# Setup utility-specific options:

# Input format
add_format_option(parser, "display the output in either grid (default), "
                  "tab, csv, or vertical format", "grid")     

# Header row
parser.add_option("-h", "--no-headers", action="store_true", dest="no_headers",
                  default=False, help="do not show column headers")

# Show my.cnf values
parser.add_option("-d", "--show-defaults", action="store_true",
                  dest="show_defaults", default=False,
                  help="show defaults from the config file per server")
Example #2
0
check_python_version()

# Constants
NAME = "MySQL Utilities - mysqldbcompare "
DESCRIPTION = "mysqldbcompare - compare databases for consistency"
USAGE = "%prog --server1=user:pass@host:port:socket " + \
        "--server2=user:pass@host:port:socket db1:db2"
PRINT_WIDTH = 75

# Check for connector/python
if not check_connector_python():
    sys.exit(1)

if __name__ == '__main__':
    # Setup the command parser
    parser = setup_common_options(os.path.basename(sys.argv[0]),
                                  DESCRIPTION, USAGE, server=False)

    # Connection information for the source server
    parser.add_option("--server1", action="store", dest="server1",
                      type="string", default=None,
                      help="connection information for first server in "
                           "the form: <user>[:<password>]@<host>[:<port>]"
                           "[:<socket>] or <login-path>[:<port>][:<socket>].")

    # Connection information for the destination server
    parser.add_option("--server2", action="store", dest="server2",
                      type="string", default=None,
                      help="connection information for second server in "
                           "the form: <user>[:<password>]@<host>[:<port>]"
                           "[:<socket>] or <login-path>[:<port>][:<socket>].")
Example #3
0
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

import os.path
import re
import sys

from mysql.utilities.command.grep import ObjectGrep, OBJECT_TYPES
from mysql.utilities.common.options import add_regexp
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.options import add_format_option

# Setup the command parser and setup server, help
parser = setup_common_options(os.path.basename(sys.argv[0]),
                              "mysqlmetagrep - search metadata",
                              "%prog --server=user:pass@host:port:socket "
                              "[options] pattern", True)

# Setup utility-specific options:
parser.add_option("-b", "--body",
                  dest="check_body", action="store_true", default=False,
                  help="search the body of routines, triggers, and events as well")

def quote(string):
    return "'" + string + "'"

# Add some more advanced parsing here to handle types better.
parser.add_option(
    '--search-objects', '--object-types', 
    dest="object_types", default=','.join(OBJECT_TYPES),
    help="the object type to search in: a comma-separated list"
Example #4
0
NAME = "MySQL Utilities - mysqluserclone "
DESCRIPTION = "mysqluserclone - clone a MySQL user account to" + \
              " one or more new users"
USAGE = "%prog --source=user:pass@host:port:socket " \
        "--destination=user:pass@host:port:socket " \
        "joe@localhost sam:secret1@localhost"

# Check for connector/python
if not check_connector_python():
    sys.exit(1)

if __name__ == '__main__':
    # Setup the command parser
    parser = setup_common_options(os.path.basename(sys.argv[0]),
                                  DESCRIPTION,
                                  USAGE,
                                  True,
                                  False,
                                  add_ssl=True)

    # Setup utility-specific options:

    # Connection information for the source server
    parser.add_option("--source",
                      action="store",
                      dest="source",
                      type="string",
                      default=None,
                      help="connection information for source server in "
                      "the form: <user>[:<password>]@<host>[:<port>]"
                      "[:<socket>] or <login-path>[:<port>][:<socket>]"
                      " or <config-path>[<[group]>].")
Example #5
0
  - The default interval for switching masters is 60 seconds.
    This value can be changed with the --switchover-interval option.

"""

# Check for connector/python
if not check_connector_python():
    sys.exit(1)

if __name__ == '__main__':
    # Setup the command parser
    program = os.path.basename(sys.argv[0]).replace(".py", "")
    parser = setup_common_options(os.path.basename(sys.argv[0]),
                                  DESCRIPTION,
                                  USAGE,
                                  True,
                                  False,
                                  extended_help=EXTENDED_HELP)

    # Setup utility-specific options:

    # Interval for reporting health
    parser.add_option("--interval",
                      "-i",
                      action="store",
                      dest="interval",
                      type="int",
                      default="15",
                      help="interval in seconds for "
                      "reporting health. Default = 15 seconds. "
                      "Lowest value is 5 seconds.")
  - You can list the users that have specific privileges using the option
    --privileges. The user must have all privileges listed in order to be
    included in the result.

  - If you specify some privileges on the --privileges option that are not
    valid for all the specified objects,  any that do not apply are not
    included in the list. For example, the SELECT privilege will be
    ignored for stored routines and the EXECUTE privilege will be ignored for
    tables but both will be taken into account for databases.

"""

if __name__ == '__main__':
    # Setup the command parser (with common options).
    parser = setup_common_options(os.path.basename(sys.argv[0]), DESCRIPTION,
                                  USAGE, append=False, server=True,
                                  server_default=None,
                                  extended_help=EXTENDED_HELP)

    # Add verbosity option (no --quite option).
    add_verbosity(parser, False)

    # Add show mode options
    parser.add_option("--show", action="store",
                      dest="show_mode", type="choice",
                      default="user_grants",
                      choices=["users", "user_grants", "raw"],
                      help="Controls the content of the report. If the value "
                           "USERS is specified, the report shows only the "
                           "list of users with any kind of grant over the "
                           "object. If USER_GRANTS is specified the reports "
                           "shows each user along with her list of privileges "
Example #7
0
    valid for all the specified objects,  any that do not apply are not
    included in the list. For example, the SELECT privilege will be
    ignored for stored routines and the EXECUTE privilege will be ignored for
    tables but both will be taken into account for databases.

  - The --inherit-level option can be used for filtering out global users, and
    also users with the same database level privileges at the object level.

"""

if __name__ == '__main__':
    # Setup the command parser (with common options).
    parser = setup_common_options(os.path.basename(sys.argv[0]),
                                  DESCRIPTION,
                                  USAGE,
                                  append=False,
                                  server=True,
                                  server_default=None,
                                  extended_help=EXTENDED_HELP)

    # Add verbosity option (no --quite option).
    add_verbosity(parser, False)

    # Add show mode options
    parser.add_option("--show",
                      action="store",
                      dest="show_mode",
                      type="choice",
                      default="user_grants",
                      choices=["users", "user_grants", "raw"],
                      help="controls the content of the report. If the value "
  - The default timeout for performing the table checksum is 5 seconds.
    This value can be changed with the --checksum-timeout option.

  - The default timeout for waiting for slaves to catch up is 300 seconds.
    This value can be changed with the --rpl-timeout option.

  - The default interval to periodically verify if a slave has read all of
    the GTIDs from the master is 3 seconds. This value can be changed
    with the --interval option.

"""

if __name__ == "__main__":
    # Setup the command parser (with common options).
    parser = setup_common_options(
        os.path.basename(sys.argv[0]), DESCRIPTION, USAGE, server=False, extended_help=EXTENDED_HELP
    )

    # Add the --discover-slaves-login option.
    add_discover_slaves_option(parser)

    # Add the --master option.
    add_master_option(parser)

    # Add the --slaves option.
    add_slaves_option(parser)

    # Add the --ssl options
    add_ssl_options(parser)

    # Add verbosity option (no --quite option).
Example #9
0
from mysql.utilities.common.options import add_format_option
from mysql.utilities.exception import UtilError


def add_pattern(option, opt, value, parser, field):
    entry = (field, value)
    try:
        getattr(parser.values, option.dest).append(entry)
    except AttributeError:
        setattr(parser.values, option.dest, [entry])


# Setup the command parser and setup server, help
parser = setup_common_options(
    os.path.basename(sys.argv[0]),
    "mysqlprocgrep - search process information",
    "%prog --server=user:pass@host:port:socket "
    "[options]", True)
# Add regexp
add_regexp(parser)

parser.add_option(
    "-Q",
    "--print-sql",
    "--sql",
    dest="print_sql",
    action="store_true",
    default=False,
    help=
    "print the statement instead of sending it to the server. If a kill option is submitted, a procedure will be generated containing the code for executing the kill."
)
Example #10
0
from mysql.utilities.common.options import parse_connection
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.options import add_verbosity
from mysql.utilities.common.options import check_format_option
from mysql.utilities.exception import UtilError

def add_pattern(option, opt, value, parser, field):
    entry = (field, value)
    try:
        getattr(parser.values, option.dest).append(entry)
    except AttributeError:
        setattr(parser.values, option.dest, [entry])

# Setup the command parser and setup server, help
parser = setup_common_options(os.path.basename(sys.argv[0]),
                              "mysqlprocgrep - search process information",
                              "%prog --server=user:pass@host:port:socket "
                              "[options]", True)
parser.add_option(
    "-G", "--basic-regexp", "--regexp",
    dest="use_regexp", action="store_true", default=False,
    help="Use 'REGEXP' operator to match pattern. Default is to use 'LIKE'.")
parser.add_option(
    "-Q", "--print-sql", "--sql",
    dest="print_sql", action="store_true", default=False,
    help="Print the statement instead of sending it to the server. If a kill option is submitted, a procedure will be generated containing the code for executing the kill.")
parser.add_option(
    "--sql-body",
    dest="sql_body", action="store_true", default=False,
    help="Only print the body of the procedure.")
parser.add_option(
    "--kill-connection",
Example #11
0
# Check Python version compatibility
check_python_version()

import os.path
import re
import sys

from mysql.utilities.command.grep import ObjectGrep, OBJECT_TYPES
from mysql.utilities.common.options import add_regexp
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.options import add_format_option

# Setup the command parser and setup server, help
parser = setup_common_options(
    os.path.basename(sys.argv[0]),
    "mysqlmetagrep - search metadata",
    "%prog --server=user:pass@host:port:socket " "[options] pattern",
    True,
)

# Setup utility-specific options:
parser.add_option(
    "-b",
    "--body",
    dest="check_body",
    action="store_true",
    default=False,
    help="search the body of routines, triggers, and events as well",
)


def quote(string):