This file is indexed.

/usr/bin/mysqldiff is in mysql-utilities 1.3.5-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#! /usr/bin/python
#
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

"""
This file contains the object diff utility which allows users to compare the
definitions of two objects and return the difference (like diff).
"""

from mysql.utilities.common.tools import check_python_version

# Check Python version compatibility
check_python_version()

import os
import re
import sys

from mysql.utilities.command.diff import object_diff, database_diff
from mysql.utilities.common.messages import PARSE_ERR_DB_OBJ_MISSING
from mysql.utilities.common.messages import PARSE_ERR_DB_OBJ_MISSING_MSG
from mysql.utilities.common.messages import PARSE_ERR_DB_OBJ_PAIR
from mysql.utilities.common.messages import PARSE_ERR_DB_OBJ_PAIR_EXT
from mysql.utilities.common.ip_parser import parse_connection
from mysql.utilities.common.options import add_difftype
from mysql.utilities.common.options import add_verbosity, check_verbosity
from mysql.utilities.common.options import add_changes_for, add_reverse
from mysql.utilities.common.options import setup_common_options
from mysql.utilities.common.pattern_matching import REGEXP_QUALIFIED_OBJ_NAME
from mysql.utilities.common.tools import check_connector_python
from mysql.utilities.exception import FormatError
from mysql.utilities.exception import UtilError

# Constants
NAME = "MySQL Utilities - mysqldiff "
DESCRIPTION = "mysqldiff - compare object definitions among objects" + \
              " where the difference is how db1.obj1 differs from db2.obj2"
USAGE = "%prog --server1=user:pass@host:port:socket " + \
        "--server2=user:pass@host:port:socket db1.object1:db2.object1 db3:db4"
PRINT_WIDTH = 75

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

# Setup the command parser
parser = setup_common_options(os.path.basename(sys.argv[0]),
                              DESCRIPTION, USAGE, False, False)

# Connection information for the source server
parser.add_option("--server1", action="store", dest="server1",
                  type="string", default="root@localhost:3306",
                  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>].")

# Add display width option
parser.add_option("--width", action="store", dest="width",
                  type="int", help="display width",
                  default=PRINT_WIDTH)

# Force mode
parser.add_option("--force", action="store_true", dest="force",
                  help="do not abort when a diff test fails")

# Skip check of table options.
parser.add_option("--skip-table-options", action="store_true",
                  dest="skip_tbl_opts",
                  help="skip check of all table options (e.g., "
                       "AUTO_INCREMENT, ENGINE, CHARSET, etc.).")

# Add verbosity and quiet (silent) mode
add_verbosity(parser, True)

# Add difftype option with SQL option
add_difftype(parser, True)

# Add the direction (changes-for)
add_changes_for(parser, None)

# Add show reverse option
add_reverse(parser)

# Now we process the rest of the arguments.
opt, args = parser.parse_args()

# Warn if quiet and verbosity are both specified
check_verbosity(opt)

# Set options for database operations.
options = {
    "quiet"            : opt.quiet,
    "verbosity"        : opt.verbosity,
    "difftype"         : opt.difftype,
    "force"            : opt.force,
    "width"            : opt.width,
    "changes-for"      : opt.changes_for,
    "reverse"          : opt.reverse,
    "skip_table_opts"  : opt.skip_tbl_opts,
}

# Parse server connection values
try:
    server1_values = parse_connection(opt.server1, None, options)
except FormatError:
    _, err, _ = sys.exc_info()
    parser.error("Server1 connection values invalid: %s." % err)
except UtilError:
    _, err, _ = sys.exc_info()
    parser.error("Server1 connection values invalid: %s." % err.errmsg)
if opt.server2 is not None:
    try:
        server2_values = parse_connection(opt.server2, None, options)
    except FormatError:
        _, err, _ = sys.exc_info()
        parser.error("Server2 connection values invalid: %s." % err)
    except UtilError:
        _, err, _ = sys.exc_info()
        parser.error("Server2 connection values invalid: %s." % err.errmsg)
else:
    server2_values = None

# Check for arguments
if len(args) == 0:
    parser.error("No objects specified to compare.")

# run the diff
diff_failed = False
arg_regexp = re.compile('{0}(?:\:){0}'.format(REGEXP_QUALIFIED_OBJ_NAME))
for argument in args:
    m_obj = arg_regexp.match(argument)
    if not m_obj:
        parser.error(PARSE_ERR_DB_OBJ_PAIR.format(db_obj_pair=argument,
                                                  db1_label='db1',
                                                  obj1_label='object1',
                                                  db2_label='db2',
                                                  obj2_label='object2'))
    db1, obj1, db2, obj2 = m_obj.groups()

    # Verify if the size of the objects matched by the REGEX is equal to the
    # initial specified string. In general, this identifies the missing use
    # of backticks.
    matched_size = len(db1)
    if obj1:
        # add 1 for the separator '.'
        matched_size = matched_size + 1
        matched_size = matched_size + len(obj1)
    # add 1 for the separator ':'
    matched_size = matched_size + 1
    matched_size = matched_size + len(db2)
    if obj2:
        # add 1 for the separator '.'
        matched_size = matched_size + 1
        matched_size = matched_size + len(obj2)
    if matched_size != len(argument):
        parser.error(PARSE_ERR_DB_OBJ_PAIR_EXT.format(db_obj_pair=argument,
                                                      db1_label='db1',
                                                      obj1_label='object1',
                                                      db2_label='db2',
                                                      obj2_label='object2',
                                                      db1_value=db1,
                                                      obj1_value=obj1,
                                                      db2_value=db2,
                                                      obj2_value=obj2))

    if (obj1 and not obj2) or (not obj1 and obj2):
        if obj1:
            detail = PARSE_ERR_DB_OBJ_MISSING.format(db_no_obj_label='db2',
                                                     db_no_obj_value=db2,
                                                     only_obj_value=obj1,
                                                     db_obj_label='db1',
                                                     db_obj_value=db1)
        else:
            detail = PARSE_ERR_DB_OBJ_MISSING.format(db_no_obj_label='db1',
                                                     db_no_obj_value=db1,
                                                     only_obj_value=obj2,
                                                     db_obj_label='db2',
                                                     db_obj_value=db2)
        parser.error(PARSE_ERR_DB_OBJ_MISSING_MSG.format(detail=detail,
                                                         db1_label='db1',
                                                         obj1_label='object1',
                                                         db2_label='db2',
                                                         obj2_label='object2'))

    # We have db1.obj:db2.obj
    if obj1:
        try:
            diff = object_diff(server1_values, server2_values,
                               "%s.%s" % (db1, obj1),
                               "%s.%s" % (db2, obj2), options)
        except UtilError:
            _, e, _ = sys.exc_info()
            print("ERROR: %s" % e.errmsg)
            sys.exit(1)
        if diff is not None:
            diff_failed = True

    # We have db1:db2
    else:
        try:
            res = database_diff(server1_values, server2_values,
                                db1, db2, options)
        except UtilError:
            _, e, _ = sys.exc_info()
            print("ERROR: %s" % e.errmsg)
            sys.exit(1)
        if not res:
            diff_failed = True

if diff_failed:
    if not opt.quiet:
        print("Compare failed. One or more differences found.")
    sys.exit(1)

if not opt.quiet:
    print("Success. All objects are the same.")

sys.exit()