--- layout: commandLine pill: cli_overview subtitle: Command-line redirect_from: /documentation/commandline/ --- # Command-line tool The Flyway command-line tool is a standalone Flyway distribution. It runs on Windows, macOS and Linux and it is primarily meant for users who wish to migrate their database from the command-line without having to integrate Flyway into their applications nor having to install a build tool. ## Download and installation
Extract the archive and simply add the new `flyway-{{site.flywayVersion}}` directory to the `PATH` to make the `flyway` command available from anywhere on your system.
$ wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/{{site.flywayVersion}}/flyway-commandline-{{site.flywayVersion}}-linux-x64.tar.gz | tar xvz && sudo ln -s `pwd`/flyway-{{site.flywayVersion}}/flyway /usr/local/bin
Or simply download the archive:
Docker $ sudo sh -c 'echo "docker run --rm flyway/flyway:{{site.flywayVersion}} $*" > /usr/local/bin/flyway && chmod +x /usr/local/bin/flyway'
(All platforms) Or simply download the image:
> docker pull flyway/flyway:{{site.flywayVersion}}
Go to Docker Hub for detailed usage instructions.
Older versions, packages without JRE and sources are available from Maven Central
Older Docker images are available from boxfuse/flyway
Extract the archive and simply add the new `flyway-{{site.flywayVersion}}` directory to the `PATH` to make the `flyway` command available from anywhere on your system.
$ wget -qO- {{site.enterpriseUrl}}/flyway-commandline/{{site.flywayVersion}}/flyway-commandline-{{site.flywayVersion}}-linux-x64.tar.gz | tar xvz && sudo ln -s `pwd`/flyway-{{site.flywayVersion}}/flyway /usr/local/bin
Or simply download the archive:
Docker $ sudo sh -c 'echo "docker run --rm redgate/flyway:{{site.flywayVersion}} $*" > /usr/local/bin/flyway && chmod +x /usr/local/bin/flyway'
(All platforms) Or simply download the image:
> docker pull redgate/flyway:{{site.flywayVersion}}
Go to Docker Hub for detailed usage instructions.
flyway-{{site.flywayVersion}}
conf
flyway.conf configuration file
drivers JDBC drivers
jars Java-based migrations (as jars)
jre
lib
licenses
sql SQL migrations
flyway macOS/Linux executable
flyway.cmd Windows executable
## Usage
> flyway [options] command
## Flyway editions
The Flyway Command-line tool distribution ships with all editions of Flyway.
It auto-detects which edition to run based on any license keys you configure,
however it can easily be configured to run the [paid editions](/download) specifically.
### Environment variable
One way to switch between the various Flyway editions is to set the `FLYWAY_EDITION` environment variable prior to
executing Flyway to any of the following values:
community | Select the Flyway Community Edition |
teams | Select the Flyway Teams Edition |
-community | Select the Flyway Community Edition |
-teams | Select the Flyway Teams Edition |
--help-h-? | Print the list of available commands and options |
--version-v | Print the Flyway version |
| Name | Description |
|---|---|
| migrate | Migrates the database |
| clean | Drops all objects in the configured schemas |
| info | Prints the details and status information about all the migrations |
| validate | Validates the applied migrations against the ones available on the classpath |
| undo Flyway Teams | Undoes the most recently applied versioned migrations |
| baseline | Baselines an existing database, excluding all migrations up to and including baselineVersion |
| repair | Repairs the schema history table |
> flyway -configFiles=path/to/myAlternativeConfig.conf migrate
To pass in multiple files, separate their names with commas:
> flyway -configFiles=path/to/myAlternativeConfig.conf,other.conf migrate
Relative paths are relative to the current working directory. The special option `-configFiles=-` reads from
standard input.
Alternatively you can also use the `FLYWAY_CONFIG_FILES` environment variable for this.
When set it will take preference over the command-line parameter.
> export FLYWAY_CONFIG_FILES=path/to/myAlternativeConfig.conf,other.conf > flyway migrateBy default Flyway loads configuration files using UTF-8. To use an alternative encoding, use the command line parameter `-configFileEncoding=` as follows:
> flyway -configFileEncoding=ISO-8859-1 migrate
Alternatively you can also use the `FLYWAY_CONFIG_FILE_ENCODING` environment variable for this.
When set it will take preference over the command-line parameter.
> export FLYWAY_CONFIG_FILE_ENCODING=ISO-8859-1
### Environment Variables
To make it easier to work with cloud and containerized environments, Flyway also supports configuration via
[environment variables](/documentation/configuration/envvars). Check out the [Flyway environment variable reference](/documentation/configuration/envvars) for details.
### Command-line Arguments
Finally, Flyway can also be configured by passing arguments directly from the command-line:
> flyway -user=myuser -schemas=schema1,schema2 -placeholders.keyABC=valueXYZ migrate
#### A note on escaping command-line arguments
Some command-line arguments will need care as specific characters may be interpreted differently depending on the
shell you are working in. The `url` parameter is particularly affected when it contains extra parameters with
equals `=` and ampersands `&`. For example:
**bash**, **macOS terminal** and **Windows cmd**: use double-quotes:
> flyway info -url="jdbc:snowflake://ab12345.snowflakecomputing.com/?db=demo_db&user=foo"
**Powershell**: use double-quotes inside single-quotes:
> ./flyway info -url='"jdbc:snowflake://ab12345.snowflakecomputing.com/?db=demo_db&user=foo"'
### Configuration from standard input
You can provide configuration options to the standard input of the Flyway command line, using the
` -configFiles=-` option. Flyway will expect such configuration to be in the same format as a configuration file.
This allows you to compose Flyway with other operations. For instance, you can decrypt a config file containing
login credentials and pipe it straight into Flyway.
#### Examples
Read a single option from `echo`:
> echo $'flyway.url=jdbc:h2:mem:mydb' | flyway info -configFiles=-
Read multiple options from `echo`, delimited by newlines:
> echo $'flyway.url=jdbc:h2:mem:mydb\nflyway.user=sa' | flyway info -configFiles=-
Use `cat` to read a config file and pipe it directly into Flyway:
> cat flyway.conf | flyway migrate -configFiles=-
Use `gpg` to encrypt a config file, then pipe it into Flyway.
Encrypt the config file:
> gpg -e -r "Your Name" flyway.conf
Decrypt the file and pipe it to Flyway:
> gpg -d -q flyway.conf.gpg | flyway info -configFiles=-
### Overriding order
The Flyway command-line tool has been carefully designed to load and override configuration in a sensible order.
Settings are loaded in the following order (higher items in the list take precedence over lower ones):
1. Command-line arguments
1. Environment variables
1. Standard input
1. Custom config files
1. `Database user: myuser Database password:If you want Flyway to connect to your database without a user or password, you can suppress prompting by adding the `-n` flag. There are exceptions, where the credentials are passed in the JDBC URL or where a password-less method of authentication is being used. ### Java Arguments If you need to to pass custom arguments to Flyway's JVM, you can do so by setting the `JAVA_ARGS` environment variable. They will then automatically be taken into account when launching Flyway. This is particularly useful when needing to set JVM system properties. ## Output By default, all debug, info and warning output is sent to `stdout`. All errors are sent to `stderr`. Flyway will automatically detect and use any logger class that it finds on its classpath that derives from any of the following: - the Apache Commons Logging framework `org.apache.commons.logging.Log` (including Log4j v1) - SLF4J `org.slf4j.Logger` - Log4J v2 `org.apache.logging.log4j.Logger` Alternatively, you can use the [loggers](/documentation/configuration/parameters/loggers) configuration parameter to specify an exact desired logging framework to use. The simplest way to make use of Flyway's auto-detection is to put all the necessary JAR files in Flyway's `lib` folder and any configuration in the Flyway root folder. For example, if you wished to use `log4j` v2 with the Flyway command line, you would achieve this by placing the log4j JAR files and the corresponding configuration file `log4j2.xml` like this:
flyway-{{site.flywayVersion}}
conf
drivers
jars
jre
lib
log4j-api-2.17.1.jar log4j v2 jar
log4j-core-2.17.1.jar log4j v2 jar
licenses
sql
log4j2.xml log4j configuration
Similarly, to use `Logback` add the relevant files like this:
flyway-{{site.flywayVersion}}
conf
drivers
jars
jre
lib
logback-classic.1.1.7.jar Logback jar
logback-core-1.1.7.jar Logback jar
slf4j-api-1.7.21.jar Logback dependency
licenses
sql
logback.xml Logback configuration
If you are building Flyway into a larger application, this means you do not need to explicitly wire up any logging as it will auto-detect one of these frameworks.
### P6Spy
P6Spy is another approach to logging which operates at the driver or datasource level, and Flyway has integration with this. You can read about setting it up [here](https://p6spy.readthedocs.io/en/latest/install.html#generic-instructions) and configuring it [here](https://p6spy.readthedocs.io/en/latest/configandusage.html#configuration-and-usage).
### Colors
By default the output is automatically colorized if `stdout` is associated with a terminal.
You can override this behavior with the `-color` option. Possible values:
- `auto` (default) : Colorize output, unless `stdout` is not associated with a terminal
- `always` : Always colorize output
- `never` : Never colorize output
### Debug output
Add `-X` to the argument list to also print debug output. If this gives you too much information, you can filter it
with normal command-line tools, for example:
**bash, macOS terminal**
> flyway migrate -X | grep -v 'term-to-filter-out'
**Powershell**
> flyway migrate -X | sls -Pattern 'term-to-filter-out' -NoMatch
**Windows cmd**
> flyway migrate -X | findstr /v /c:"term-to-filter-out"
### Quiet mode
Add `-q` to the argument list to suppress all output, except for errors and warnings.
### Machine-readable output
Add `-outputType=json` to the argument list to print JSON instead of human-readable output. Errors are included in the JSON payload instead of being sent to `stderr`.
### Writing to a file
Add `-outputFile=/my/output.txt` to the argument list to also write output to the specified file.
{% include downloadpopup.html %}