IntelliTree CLI extension to MySQLDiff
This is a command line tool to compare the schema of 2 databases and generate an SQL-ALTER script that can be run to update the schema of one of the databases to match the other. MySQLDiff 1.5.0 (http://www.mysqldiff.org/) already did this, but it only worked interactively over a web app. Our extension provides the functionality via command line so it can be used in scripts.
The original MySqlDiff has not been modified – only two new files have been added: mysqldiff.php and ini.php.
Usage:
Although both the source and target databases must be specified with their database dump files, MySQLDiff requires a database connection with enough privileges to create a temporary database so that it can process them!
- The script can be called either from command line or from the browser.
- In the former case, it can take parameters either from an ini file, or from the command line, or from both.
- In the latter case, it can take parameters either from an ini file, or from the query string, or from both.
- The parameters in the command line/query string always override those read from the ini file.
- The ini file is called ini.php, the script itself is mysqldiff.php.
- The resulting alter script will be either written to stdout, or in an output file or displayed in the browser.
Examples of calling the script from the command line:
# this runs with parameters taken solely from 'ini.php': php mysqldiff.php # this runs with parameters taken from an other ini file: php mysqldiff.php --iniFile=/some/path/other.ini.php # this runs with parameters mostly read from 'ini.php' and some of them are overridden by the command line: php mysqldiff.php --source=db1.sql --target=db2.sql
Examples of calling the script from the browser:
# this runs with parameters taken solely from 'ini.php': http://path/to/mysqldiff/mysqldiff.php # this runs with parameters mostly read from 'ini.php' and some of them are overridden by the command line: http://path/to/mysqldiff/mysqldiff.php?source=db1.sql&target=db2.sql # you can suppress any output messages but the fatal errors with specifying the 'silent' # parameter either in the command line, or in the query string. E.g.: http://path/to/mysqldiff/mysqldiff.php?silent=1 php mysqldiff.php -silent # you can display a help text with specifying the 'help' parameter. E.g.: http://path/to/mysqldiff/mysqldiff.php?help=1 php mysqldiff.php --help=1 php mysqldiff.php help php mysqldiff.php -help
The available parameters and their default values are the following (you can find and also set them in ini.php!):
// Database host name: "hostName"=>"localhost", // Database user name: "dbUser"=>"root", // Database password: "dbUserPw"=>"", // Dump file of the source database: "source"=>"", // Live source database. If specified, it overrides the 'source' parameter: "sourceDb"=>"", // Dump file of the target database: "target"=>"", // Live target database. If specified, it overrides the 'target' parameter: "targetDb"=>"", // Output file name. The result will be written to stdout (or displayed in the browser) if left blank: "output"=>"", ////////////////////////////////////////////////////////////////////////////////////////////////// // Options: ////////////////////////////////////////////////////////////////////////////////////////////////// // Change table type "type"=>1, // Alter table options "options"=>1, // Consider auto_increment parameter "auto_incr"=>0, // Alter table charset "charset"=>1, // Alter comments "comment"=>1, // Generate hint on changes in attribute format "changes"=>1, // Move foreign keys to the end of script "cfk_back"=>1, // Deactivate foreign key checks before script run. "no_cfk_checks"=>1, // Use Backticks for table and attribute names "backticks"=>0, // Create INSERT-statements for the tables "data_insert"=>0, // Create REPLACE-statements for the tables "data_replace"=>0, // Merge statements "short"=>1,
IntelliTree