Fresh mysql database to liquibase

What I have:

  • mariaDB installed and liquibase command line installed on a CentOS machine locally.
    (not in docker or anything like that).
  • A set of SQL files that can be ran in order to create a fresh mysql database locally inside of mariaDB.
    (No data in the database, just tables with columns)

What I need:

  • Some way of creating the initial schema in liquibase from this newly created mysql database.

Problems:

  • I’ve never touched liquibase before so have no clue how any of it works.
  • I’ve looked through running some generateChangelog command, but that seems to fail with:

SEVERE: Unexpected error running Liquibase: Unexpected value ‘generate-changelog’ (options must start with a ‘–’)

  • I’ve looked at the Get Started with Liquibase and SQL page and have the same error when trying to run the init command.
  • All online help that I’ve found on this seems to either be done on windows, through docker containers, includes some form of springboot application or doesn’t have enough info on the full process in order to simply get from A to B by following steps.

I’d assume that this is something a fair amount of people do in order to get up and running from a current database into using liquibase, so I’m hoping that the process is really simple and that I’m just missing something obvious.

Hi @JamesB,

Sorry to hear that you are having trouble getting started, but welcome to Liquibase.

Have you seen this page? https://docs.liquibase.com/start/tutorials/mariadb.html

You might also be interested in this page: https://docs.liquibase.com/commands/inspection/generate-changelog.html

There’s a video at the top of the page. Starting around 2:00 in the video it describes how to do generate-changelog.

Does that help?

-PJ

So I managed to get someone with a fair bit of experience to help out with the command line needed and now have this working.

For anyone who gets stuck with this, it seems that the command line is slightly different in my case, where the ‘generate-changelog’ command is actually ‘generateChangeLog’ and needs to go after all of the parameters had been defined, rather than before, like I would have expected.

So:
liquibase --changeLogFile=“{Location to save the file to}/myChangeLog.xml” --username={Database username} --password={Database Password} --url=“jdbc:mariadb://localhost:{port}/{database name}” --classpath={Location of mariadb-java-client-3.1.4.jar} generateChangeLog

(You can get the client jar file from the mvnrepository web site)
That creates the initial Schema changelog so that you can recreate the database structure using the .xml file.

If you want the data that was in there, then you need to use --diffTypes=“data” as a extra parameter, and save to a different changelog.

With this you can then pull the data changes into the main .xml change log if you want the database to be populated after the tables and columns etc being created

1 Like