.TH "MYSQLDIFF" "1" "May 09, 2012" "1.0.3" "MySQL Utilities" .SH NAME mysqldiff \- Identify differences among database objects . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .\" Man page generated from reStructeredText. . .SH SYNOPSIS .sp .nf .ft C mysqldiff [options] {db1[:db1] | db1.obj1[:db2.obj2]} ... .ft P .fi .SH DESCRIPTION .sp This utility reads the definitions of objects and compares them using a diff\-like method to determine whether they are the same. The utility displays the differences for objects that are not the same. .sp Use the notation db1:db2 to name two databases to compare, or, alternatively just db1 to compare two databases with the same name. The latter case is a convenience notation for comparing same\-named databases on different servers. .sp The comparison may be run against two databases of different names on a single server by specifying only the \fI\%--server1\fP option. The user can also connect to another server by specifying the \fI\%--server2\fP option. In this case, db1 is taken from server1 and db2 from server2. .sp When a database pair is specified, all objects in one database are compared to the corresponding objects in the other. Any objects not appearing in either database produce an error. .sp To compare a specific pair of objects, add an object name to each database name in \fIdb.obj\fP format. For example, use \fBdb1.obj1:db2.obj2\fP to compare two named objects, or db1.obj1 to compare an object with the same name in databases with the same name. It is not legal to mix a database name with an object name. For example, \fBdb1.obj1:db2\fP and \fBdb1:db2.obj2\fP are illegal. .sp The comparison may be run against a single server for comparing two databases of different names on the same server by specifying only the \fI\%--server1\fP option. Alternatively, you can also connect to another server by specifying the \fI\%--server2\fP option. In this case, the first object to compare is taken from server1 and the second from server2. .sp By default, the utilty generates object differences as a difference report. However, you can generate a transformation report containing SQL statements for transforming the objects for conformity instead. Use the \(aqsql\(aq value for the \fI\%--difftype\fP option to produce a listing that contains the appropriate ALTER commands to conform the object definitions for the object pairs specified. If a transformation cannot be formed, the utility reports the diff of the object along with a warning statement. See important limitations in the NOTES section. .sp To specify how to display diff\-style output, use one of the following values with the \fI\%--difftype\fP option: .INDENT 0.0 .TP .B \fBunified\fP (default) Display unified format output. .TP .B \fBcontext\fP Display context format output. .TP .B \fBdiffer\fP Display differ\-style format output. .TP .B \fBsql\fP Display SQL transformation statement output. .UNINDENT .sp The \fI\%--changes-for\fP option controls the direction of the difference (by specifying the object to be transformed) in either the difference report (default) or the transformation report (designated with the \fI\-\-difftype=sql\fP option). Consider the following command: .sp .nf .ft C mysqldiff \-\-server1=root@host1 \-\-server2=root@host2 \-\-difftype=sql \e db1.table1:dbx.table3 .ft P .fi .sp The leftmost database (\fBdb1\fP) exists on the server designated by the \fI\%--server1\fP option (\fBhost1\fP). The rightmost database (\fBdbx\fP) exists on the server designated by the \fI\%--server2\fP option (\fBhost2\fP). .INDENT 0.0 .IP \(bu 2 \fI\-\-changes\-for=server1\fP: Produce output that shows how to make the definitions of objects on \fBserver1\fP like the definitions of the corresponding objects on \fBserver2\fP. .IP \(bu 2 \fI\-\-changes\-for=server2\fP: Produce output that shows how to make the definitions of objects on \fBserver2\fP like the definitions of the corresponding objects on \fBserver1\fP. .UNINDENT .sp The default direction is \fBserver1\fP. .sp For \fBsql\fP difference format, you can also see the reverse transformation by specifying the \fI\%--show-reverse\fP option. .sp The utility stops on the first occurrence of missing objects or when an object does not match. To override this behavior, specify the \fI\-\-force\fP option to cause the utility to attempt to compare all objects listed as arguments. .SH OPTIONS .sp \fBmysqldiff\fP accepts the following command\-line options: .INDENT 0.0 .TP .B \-\-help Display a help message and exit. .UNINDENT .INDENT 0.0 .TP .B \-\-changes\-for= Specify the server to show transformations to match the other server. For example, to see the transformation for transforming object definitions on server1 to match the corresponding definitions on server2, use \fI\-\-changes\-for=server1\fP. Permitted values are \fBserver1\fP and \fBserver2\fP. The default is \fBserver1\fP. .UNINDENT .INDENT 0.0 .TP .B \-\-difftype=, \-d Specify the difference display format. Permitted format values are \fBunified\fP, \fBcontext\fP, \fBdiffer\fP, and \fBsql\fP. The default is \fBunified\fP. .UNINDENT .INDENT 0.0 .TP .B \-\-force Do not halt at the first difference found. Process all objects to find all differences. .UNINDENT .INDENT 0.0 .TP .B \-\-quiet, \-q Do not print anything. Return only an exit code of success or failure. .UNINDENT .INDENT 0.0 .TP .B \-\-server1= Connection information for the first server in <\fIuser\fP>[:<\fIpasswd\fP>]@<\fIhost\fP>[:<\fIport\fP>][:<\fIsocket\fP>] format. .UNINDENT .INDENT 0.0 .TP .B \-\-server2= Connection information for the second server in <\fIuser\fP>[:<\fIpasswd\fP>]@<\fIhost\fP>[:<\fIport\fP>][:<\fIsocket\fP>] format. .UNINDENT .INDENT 0.0 .TP .B \-\-show\-reverse Produce a transformation report containing the SQL statements to conform the object definitions specified in reverse. For example, if \fI\%--changes-for\fP is set to server1, also generate the transformation for server2. Note: The reverse changes are annotated and marked as comments. .UNINDENT .INDENT 0.0 .TP .B \-\-verbose, \-v Specify how much information to display. Use this option multiple times to increase the amount of information. For example, \fI\-v\fP = verbose, \fI\-vv\fP = more verbose, \fI\-vvv\fP = debug. .UNINDENT .INDENT 0.0 .TP .B \-\-version Display version information and exit. .UNINDENT .INDENT 0.0 .TP .B \-\-width= Change the display width of the test report. The default is 75 characters. .UNINDENT .SH NOTES .sp You must provide connection parameters (user, host, password, and so forth) for an account that has the appropriate privileges to access all objects to be compared. .sp The SQL transformation feature has these known limitations: .INDENT 0.0 .IP \(bu 2 When tables with partition differences are encountered, the utility generates the \fBALTER TABLE\fP statement for all other changes but prints a warning and omits the partition differences. .IP \(bu 2 If the transformation detects table options in the source table (specified with the \fI\%--changes-for\fP option) that are not changed or do not exist in the target table, the utility generates the \fBALTER TABLE\fP statement for all other changes but prints a warning and omits the table option differences. .IP \(bu 2 Rename for events is not supported. This is because \fBmysqldiff\fP compares objects by name. In this case, depending on the direction of the diff, the event is identified as needing to be added or a \fBDROP EVENT\fP statement is generated. .IP \(bu 2 Changes in the definer clause for events are not supported. .IP \(bu 2 SQL extensions specific to MySQL Cluster are not supported. .UNINDENT .sp For the \fI\%--difftype\fP option, the permitted values are not case sensitive. In addition, values may be specified as any unambiguous prefix of a valid value. For example, \fI\-\-difftype=d\fP specifies the differ type. An error occurs if a prefix matches more than one valid value. .SH EXAMPLES .sp To compare the \fBemployees\fP and \fBemp\fP databases on the local server, use this command: .sp .nf .ft C $ mysqldiff \-\-server1=root@localhost employees:emp1 # server1 on localhost: ... connected. WARNING: Objects in server1:employees but not in server2:emp1: EVENT: e1 Compare failed. One or more differences found. $ mysqldiff \-\-server1=root@localhost \e employees.t1:emp1.t1 employees.t3:emp1.t3 # server1 on localhost: ... connected. # Comparing employees.t1 to emp1.t1 [PASS] # server1 on localhost: ... connected. # Comparing employees.t3 to emp1.t3 [PASS] Success. All objects are the same. $ mysqldiff \-\-server1=root@localhost \e employees.salaries:emp1.salaries \-\-differ # server1 on localhost: ... connected. # Comparing employees.salaries to emp1.salaries [FAIL] # Object definitions are not the same: CREATE TABLE \(gasalaries\(ga ( \(gaemp_no\(ga int(11) NOT NULL, \(gasalary\(ga int(11) NOT NULL, \(gafrom_date\(ga date NOT NULL, \(gato_date\(ga date NOT NULL, PRIMARY KEY (\(gaemp_no\(ga,\(gafrom_date\(ga), KEY \(gaemp_no\(ga (\(gaemp_no\(ga) \- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ? ^^^^^ + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ? ++ ^^^ Compare failed. One or more differences found. .ft P .fi .sp The following examples show how to generate a transformation report. Assume the following object definitions: .sp Host1: .sp .nf .ft C CREATE TABLE db1.table1 (num int, misc char(30)); .ft P .fi .sp Host2: .sp .nf .ft C CREATE TABLE dbx.table3 (num int, notes char(30), misc char(55)); .ft P .fi .sp To generate a set of SQL statements that transform the definition of \fBdb1.table1\fP to \fBdbx.table3\fP, use this command: .sp .nf .ft C $ mysqldiff \-\-server1=root@host1 \-\-server2=root@host2 \e \-\-changes\-for=server1 \-\-difftype=sql \e db1.table1:dbx.table3 # server1 on host1: ... connected. # server2 on host2: ... connected. # Comparing db1.table1 to dbx.table3 [FAIL] # Transformation statments: ALTER TABLE db1.table1 ADD COLUMN notes char(30) AFTER a, CHANGE COLUMN misc misc char(55); Compare failed. One or more differences found. .ft P .fi .sp To generate a set of SQL statements that transform the definition of \fBdbx.table3\fP to \fBdb1.table1\fP, use this command: .sp .nf .ft C $ mysqldiff \-\-server1=root@host1 \-\-server2=root@host2 \e \-\-changes\-for=server2 \-\-difftype=sql \e db1.table1:dbx.table3 # server1 on host1: ... connected. # server2 on host2: ... connected. # Comparing db1.table1 to dbx.table3 [FAIL] # Transformation statments: ALTER TABLE dbx.table3 DROP COLUMN notes, CHANGE COLUMN misc misc char(30); Compare failed. One or more differences found. .ft P .fi .sp To generate a set of SQL statements that transform the definitions of \fBdbx.table3\fP and \fBdb1.table1\fP in both directions, use this command: .sp .nf .ft C $ mysqldiff \-\-server1=root@host1 \-\-server2=root@host2 \e \-\-show\-reverse \-\-difftype=sql \e db1.table1:dbx.table3 # server1 on host1: ... connected. # server2 on host2: ... connected. # Comparing db1.table1 to dbx.table3 [FAIL] # Transformation statments: # \-\-destination=server1: ALTER TABLE db1.table1 ADD COLUMN notes char(30) AFTER a, CHANGE COLUMN misc misc char(55); # \-\-destination=server2: # ALTER TABLE dbx.table3 # DROP COLUMN notes, # CHANGE COLUMN misc misc char(30); Compare failed. One or more differences found. .ft P .fi .SH COPYRIGHT .sp Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. .sp 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. .sp 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. .sp 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 .SH AUTHOR MySQL Utilities Team .SH COPYRIGHT 2010, Oracle and/or its affiliates. All rights reserved. .\" Generated by docutils manpage writer. .\" .