Automate schema comparison and synchronization from the command line

dbForge Schema Compare supports a command-line interface, which means that you can automate schema comparison and synchronization operations through the command line.

Note

To run the Command Line in Windows 11:

From the Windows taskbar

  • Right-click the taskbar at the bottom of the screen and then select Run. or
  • Click Start or press the Windows key on your keyboard to open the Start menu.
  • Type cmd or Command Prompt in the search bar.
  • Select the Command Prompt app from the search results to open it.

Using shortcut keys

  • Press the Windows + R keys, to show the Run command window.
  • In the window that opens, type cmd and press Enter.

Command line basics

To access the dbForge Schema Compare for MySQL functionality from the command line, you need to navigate to the schemacompare.com file, located in the tool’s installation folder on your PC. For example:

cd C:\Program Files\Devart\dbForge Compare Bundle for MySQL Standard\dbForge Schema Compare for MySQL

Get help

To see a quick help on the arguments available in the command line, type the following:

schemacompare.com /?

Help in cmd

To get detailed information about each command-line operation, execute the following command and specify the desired option value schemacompare /option_name /?. For example, schemacompare /backup /?.

Enter commands

You can interact with dbForge Schema Compare for MySQL via the command line in three ways:

1. Enter all the arguments directly in the Command Prompt. For example:

/schemacompare /source host:<server_name> database:<database_name> [port:<port>] user:<user_name> [password:<password>] [charset:<charset>] /target host:<server_name> database:<database_name> [port:<port>] user:<user_name> password:<password> [charset:<charset>] 

2. Specify the path to the comparison document you’ve saved previously. This uses both the connection and comparison settings defined in the document.

/schemacompare /compfile:"D:\file_name.scomp"

If you need to use parameters not specified in the file, add them in the Command Prompt. For example:

/schemacompare /compfile:"D:\file_name.scomp" /report:"report.txt"

3. Enter the path to a file containing the required command-line arguments. For instructions on how to prepare the file, see the information provided below. For example:

/argfile:"D:\file_name.txt"

If you need to use parameters not specified in the file, add them in the Command Prompt. For example:

C:\Program Files\Devart\Compare Bundle for MySQL\dbForge Schema Compare for MySQL>schemacompare.com /schemacompare /argfile:file_name.txt /sync

Prepare a file with command-line arguments

To create a .txt file with command-line arguments for Schema Compare, you have two options: manually create the file or automatically generate it from the Schema Compare GUI.

Create a .txt file with command-line arguments manually

1. Open a text editor, such as Notepad in Windows.

2. Enter your command-line arguments into the editor. These should mirror the syntax you’d use in the command prompt, including all necessary parameters for your schema comparison task.

3. Save the file with a clear name and a .txt extension.

Generate a .txt file with command-line arguments from the GUI

To generate a .txt file with command-line arguments automatically:

1. Open the Schema Comparison wizard using one of the following ways:

  • On the standard toolbar, click New Schema Comparison.
  • On the Start page, click New Schema Comparison.
  • On the File menu, click New > New Schema Comparison.
  • On the standard toolbar, click Edit Comparison if you want to generate a file for the already executed schema comparison and want to change comparison properties.

2. On the Source and Target page of the wizard, select the source and target data sources you want to compare.

3. Optional: You can go through other wizard pages to configure the data comparison.

4. On the Options page, click Save settings to a command line arguments file in the upper right corner. In the Save As window that opens, specify the file name and location to save the file and then click Save.

Generate a file with command-line arguments from the GUI

The selected Source and Target connection strings along with comparison options will be saved as a .txt file with command-line arguments. You can edit the values of comparison options in the file as described in Options used in the command line.

Note

The generated file will not contain password information for security purposes. You should edit the file and enter the passwords manually.

Create a .bat file with command-line arguments

A .bat file is a type of script file used to automate tasks on Windows operating systems. It contains a series of commands that the Windows Command Prompt can execute sequentially. You can create a .bat file containing the Schema Compare commands right from the tool’s GUI.

1. Open the Schema Comparison wizard using one of the following ways:

  • On the standard toolbar, click New Schema Comparison.
  • On the Start page, click New Schema Comparison.
  • On the File menu, click New > New Schema Comparison.
  • On the standard toolbar, click Edit Comparison if you want to generate a file for the already executed schema comparison and want to change comparison properties.

2. On the Source and Target page of the wizard, select the source and target data sources you want to compare.

3. Optional: You can go through other wizard pages to configure the data comparison.

4. On the Options page, click to open the Save dropdown in the lower left corner. Then select Save Command Line.

5. In the Command line execution file settings dialog that opens, review the automatically generated settings and modify them if required. To validate the generated command line, click Validate. Once done, click Save.

6. Specify the file name and location to save the file and then click Save.

Save a .bat file with command-line arguments

Generate the output file name dynamically

When using dbForge Schema Compare from the command line, you can configure the tool to automatically append the current timestamp to the names of output files, such as reports or logs. This ensures each file has a unique name based on its creation time, simplifying file organization and identification.

1. Add the following command to the .bat file with the Schema Compare arguments.

SET TimeStamp=%date:~6,4%-%date:~3,2%-%date:~0,2%-0%time:~1,1%-%time:~3,2%-%time:~6,2%

This command generates a timestamp string from the current system date and time, then assigns it to a variable named TimeStamp.

2. Add a variable to the output files names. For example: Log_File%TimeStamp%.log or Update_Script%TimeStamp%.sql.

The whole script might look as follows:

SET TimeStamp=%date:~6,4%-%date:~3,2%-%date:~0,2%-0%time:~1,1%-%time:~3,2%-%time:~6,2%

"C:\Program Files\Devart\dbForge Compare Bundle for MySQL Standard\dbForge Schema Compare for MySQL\schemacompare.com" /schemacompare /source connection:"User Id=root;Host=dbfmylast;Database=sakila;Character Set=utf8" /target connection:"User Id=root;Host=localhost;Database=sakila;Character Set=utf8" /log:"D:\Log_File_%TimeStamp%.log" /sync:"Update_Script_%TimeStamp%.sql"

Log file with a dynamic name

Simple examples of using the command line

Perform schema comparison using the settings specified in the .scomp file:

/schemacompare /compfile:"D:\file_name.scomp"

Perform a schema comparison using the command-line arguments specified in the file_name.txt file.

/schemacompare /argfile:"D:\file_name.txt"

Compare databases using the provided connection details:

schemacompare.com /schemacompare /source connection:"user Id=your_id;password=your_password;host=your_host;Character Set=utf8;port=3306;database=database_name" /target connection:"user Id=your_id;host=your_host;Character Set=utf8;port=3306;database=database_name;password=your_password

Perform schema comparison using the command-line arguments specified in the file_name.txt file and save the log output to the specified file:

/schemacompare /argfile:"D:\file_name.txt" /log:"C:\MyLog.log"

Perform schema comparison using the settings specified in the .scomp file and save the comparison report to the specified HTML file:

/schemacompare /compfile:"D:\file_name.scomp" /report:"C:\Report.html"

Perform schema comparison and synchronization using the command-line arguments specified in the file_name.txt file:

/schemacompare /argfile:"D:\file_name.txt" /sync

Perform schema comparison using the command-line arguments specified in the file_name.txt file and save a synchronization script:

/schemacompare /argfile:"D:\file_name.txt" /sync:"C:\sync_script_name.sql"