Database CI/CD and Schema Migration with MySQL and GitHub

Estimated: 30 mins
Database CI/CD and Schema Migration with MySQL and GitHub

A series of articles about Database CI/CD and Schema Migration with MySQL


In the last article Database CI/CD and Schema Migration with MySQL, you have tried UI workflow in Bytebase.

This tutorial will bring your MySQL schema change to the next level by introducing the GitOps workflow, where you commit the schema change script to the GitHub repository, which will in turn trigger the schema deployment pipeline in Bytebase.

You can use Bytebase free version to finish the tutorial.


Before you start this tutorial, make sure you have the following ready:

Step 1 - Run Bytebase in Docker and set the External URL generated by ngrok

ngrok is a reverse proxy tunnel, and in our case, we need it for a public network address in order to receive webhooks from VCS. ngrok we used here is for demonstration purposes. For production use, we recommend using Caddy.


  1. Run Bytebase in Docker with the following command:

    docker run --rm --init \
      --name bytebase \
      --publish 8080:8080 --pull always \
      --volume ~/.bytebase/data:/var/opt/bytebase \
  2. Bytebase is running successfully in Docker, and you can visit it via localhost:8080. Register an admin account and it will be granted the workspace admin role automatically.

  3. Login to ngrok Dashboard and complete the Getting Started steps to install and configure. If you want to use the same domain each time you launch ngrok, go to Cloud Edge > Domains, where you'll find the domain <<YOURS>> linked to your account.

  4. Run the ngrok command ngrok http --domain=<<YOURS>> 8080 to start ngrok with your specific domain, and you will see the output displayed below:


  5. Log in Bytebase and click the gear icon (Settings) on the top right. Click General under Workspace. Paste <<YOURS>> as External URL under Network section and click Update.


  6. Now you can access Bytebase via <<YOURS>>

Step 2 - Find your MySQL in Bytebase

  1. Visit Bytebase Console through the browser via your ngrok URL. Log in using your account created from the previous tutorial. login

  2. If you followed the previous tutorial, you should see that the project and database created are still in your workspace. home

Step 3 - Connect Bytebase with

  1. Go to Settings and choose Version Control from the left sidebar. vc-settings-1

  2. Choose and Click Next.

  3. In this tutorial, we will need your GitHub personal account instead of an organization account STEP 2 - OAuth application info. The configuration is similar.

  4. Go to your GitHub account's Settings page.

  5. Click Developer Settings at the bottom of the left sidebar. Click OAuth Apps, and add a New OAuth App. github-oauth-apps

  6. Fill Application name and then copy the Homepage and Authorization callback URL in Bytebase and fill them in. Click Register application. vc-settings-2 github-new-oauth

  7. After the OAuth application is created, click Generate a new client secret. Copy the Client ID and the newly generated Client Secret, paste them back into Bytebase's Application ID and Secret. github-client-id-secrets bb-app-id-secrets

  8. Click Next. You will be redirected to the confirmation page. Click Confirm and add, and the Git provider is successfully added. settings-vc-git-provider-added

Step 4 - Enable GitOps workflow with MySQL

  1. Go to your project, click Version Control, and choose GitOps Workflow. Click Configure GitOps. enable-gitops

  2. Choose - the provider you just added. It will display all the repositories you can manipulate. Choose the one you'd like to make changes to. For the sake of this tutorial, let's keep the rest of the settings default, and click Finish. gitops-enabled

Step 5 - Change schema for MySQL by pushing SQL schema change files to GitHub

  1. In your GitHub repository MySQL-test-bb-local, create a folder bytebase, and create a SQL file using the naming convention {{ENV_ID}}/{{DB_NAME}}##{{VERSION}}##{{TYPE}}##{{DESCRIPTION}}.sql. It is the default configuration for the file path template setting in the last step. The full file path is bytebase/test/uni##202302071000##ddl##create_table.sql:
  • test corresponds to {{ENV_ID}}
  • uni corresponds to {{DB_NAME}}
  • 202302071000 corresponds to {{VERSION}}
  • ddl corresponds to {{TYPE}}
  • create_table corresponds to {{DESCRIPTION}}

Let's create a table subject.

   course VARCHAR(255)


  1. Commit and push this file.

  2. Go to your project in Bytebase. You’ll find there is a push event and an auto-created issue [uni] Alter schema.


  1. Go to the issue page, you’ll see:
  • The issue is created via GitHub.
  • The issue is completed without manual approval because it applies the schema change to a database from the Test environment, which doesn't require manual approval.
  • The SQL is exactly the one we have committed to the GitHub repository.
  • The Assignee is Bytebase, because it’s automatic. If the github user you use to commit the change has the same email address found in the bytebase member list, we will use that member as the assignee.


  1. Click View change, you can see the differences. diff

  2. Go to your GitHub repository, you will see besides your committed SQL, there is a .uni##LATEST.sql file. Because you have configured Schema path template before, Bytebase will write back the latest schema to that specified path after completing the schema change. Thus you have access to an update-to-date full schema at any time. latest-schema

  3. Let’s create another SQL file uni##202302072000##ddl##add_lecturer.sql to see how that latest schema file will be updated after applying a new schema change. Paste the SQL script in it.

ALTER TABLE subject ADD lecturer VARCHAR(255);
  1. After pushing and committing the new SQL file, go back to Bytebase and you should find another newly generated issue. issue-add-column

  2. Click View change and see the difference. diff-columns

  3. Go back to your GitHub repository and you will find the LATEST SQL has been updated to reflect the latest schema. latest-schema-lecturer

Summary and What's Next

Now that you have tried the GitOps workflow, which stores your MySQL schema in GitHub and trigger the change upon committing change to the repository, to bring your MySQL change workflow to the next level of Database DevOps - Database as Code.

You can check out GitOps docs to learn more configuration details.

In the real world, you might have separated feature and main branches corresponding to your development and production environment, you can check out GitOps with Feature Branch Workflow to learn the setup. Have a try and look forward to your feedback!

Edit this page on GitHub

Subscribe to Newsletter

By subscribing, you agree with Bytebase's Terms of Service and Privacy Policy.