Skip to content

Commit ae76269

Browse files
author
Shuode Li
committed
Support Azure Database for MySQL.
1 parent ea339b6 commit ae76269

File tree

11 files changed

+41
-6
lines changed

11 files changed

+41
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Also see:
6565
- [the fine print](doc/the-fine-print.md)
6666
- [Community questions](https://github.com/github/gh-ost/issues?q=label%3Aquestion)
6767
- [Using `gh-ost` on AWS RDS](doc/rds.md)
68+
- [Using `gh-ost` on Azure Database for MySQL](doc/azure.md)
6869

6970
## What's in a name?
7071

doc/azure.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
`gh-ost` has been updated to work with Azure Database for MySQL however due to GitHub does not use it, this documentation is community driven so if you find a bug please [open an issue][new_issue]!
2+
3+
# Azure Database for MySQL
4+
5+
## Limitations
6+
7+
- `gh-ost` runs should be setup use [`--assume-rbr`][assume_rbr_docs] and use `binlog_row_image=FULL`.
8+
- Azure Database for MySQL does not use same user name suffix for master and replica, so master host, user and password need to be pointed out.
9+
10+
## Step
11+
1. Change the replica server's `binlog_row_image` from `MINIMAL` to `FULL`. See [guide](https://docs.microsoft.com/en-us/azure/mysql/howto-server-parameters) on Azure document.
12+
2. Use your `gh-ost` always with additional 5 parameter
13+
```{bash}
14+
gh-ost \
15+
--azure \
16+
--assume-master-host=master-server-dns-name \
17+
--master-user="master-user-name" \
18+
--master-password="master-password" \
19+
--assume-rbr \
20+
[-- other paramters you need]
21+
```
22+
23+
24+
[new_issue]: https://github.com/github/gh-ost/issues/new
25+
[assume_rbr_docs]: https://github.com/github/gh-ost/blob/master/doc/command-line-flags.md#assume-rbr
26+
[migrate_test_on_replica_docs]: https://github.com/github/gh-ost/blob/master/doc/cheatsheet.md#c-migratetest-on-replica

doc/command-line-flags.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ A more in-depth discussion of various `gh-ost` command line flags: implementatio
66

77
Add this flag when executing on Aliyun RDS.
88

9+
### azure
10+
11+
Add this flag when executing on Azure Database for MySQL.
12+
913
### allow-master-master
1014

1115
See [`--assume-master-host`](#assume-master-host).

doc/requirements-and-limitations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The `SUPER` privilege is required for `STOP SLAVE`, `START SLAVE` operations. Th
4141
- Amazon RDS works, but has its own [limitations](rds.md).
4242
- Google Cloud SQL works, `--gcp` flag required.
4343
- Aliyun RDS works, `--aliyun-rds` flag required.
44+
- Azure Database for MySQL works, `--azure` flag required, and have detailed document about it. (azure.md)
4445

4546
- Multisource is not supported when migrating via replica. It _should_ work (but never tested) when connecting directly to master (`--allow-on-master`)
4647

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type MigrationContext struct {
9595
DiscardForeignKeys bool
9696
AliyunRDS bool
9797
GoogleCloudPlatform bool
98+
AzureMySQL bool
9899

99100
config ContextConfig
100101
configMutex *sync.Mutex

go/base/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig,
7676
}
7777
// AliyunRDS set users port to "NULL", replace it by gh-ost param
7878
// GCP set users port to "NULL", replace it by gh-ost param
79-
if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform {
79+
// Azure MySQL set users port to a different value by design, replace it by gh-ost para
80+
if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform || migrationContext.AzureMySQL {
8081
port = connectionConfig.Key.Port
8182
} else {
8283
portQuery := `select @@global.port`

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func main() {
7777
flag.BoolVar(&migrationContext.SkipStrictMode, "skip-strict-mode", false, "explicitly tell gh-ost binlog applier not to enforce strict sql mode")
7878
flag.BoolVar(&migrationContext.AliyunRDS, "aliyun-rds", false, "set to 'true' when you execute on Aliyun RDS.")
7979
flag.BoolVar(&migrationContext.GoogleCloudPlatform, "gcp", false, "set to 'true' when you execute on a 1st generation Google Cloud Platform (GCP).")
80+
flag.BoolVar(&migrationContext.AzureMySQL, "azure", false, "set to 'true' when you execute on Azure Database on MySQL.")
8081

8182
executeFlag := flag.Bool("execute", false, "actually execute the alter & migrate the table. Default is noop: do some tests and exit")
8283
flag.BoolVar(&migrationContext.TestOnReplica, "test-on-replica", false, "Have the migration run on a replica, not on the master. At the end of migration replication is stopped, and tables are swapped and immediately swap-revert. Replication remains stopped and you can compare the two tables for building trust")

go/logic/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (this *Applier) InitDBConnections() (err error) {
8989
if err := this.validateAndReadTimeZone(); err != nil {
9090
return err
9191
}
92-
if !this.migrationContext.AliyunRDS && !this.migrationContext.GoogleCloudPlatform {
92+
if !this.migrationContext.AliyunRDS && !this.migrationContext.GoogleCloudPlatform && !this.migrationContext.AzureMySQL {
9393
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
9494
return err
9595
} else {

go/logic/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (this *Inspector) InitDBConnections() (err error) {
5353
if err := this.validateConnection(); err != nil {
5454
return err
5555
}
56-
if !this.migrationContext.AliyunRDS && !this.migrationContext.GoogleCloudPlatform {
56+
if !this.migrationContext.AliyunRDS && !this.migrationContext.GoogleCloudPlatform && !this.migrationContext.AzureMySQL {
5757
if impliedKey, err := mysql.GetInstanceKey(this.db); err != nil {
5858
return err
5959
} else {

go/mysql/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,5 @@ func (this *ConnectionConfig) GetDBUri(databaseName string) string {
116116
if this.tlsConfig != nil {
117117
tlsOption = TLS_CONFIG_KEY
118118
}
119-
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?interpolateParams=%t&autocommit=true&charset=utf8mb4,utf8,latin1&tls=%s", this.User, this.Password, hostname, this.Key.Port, databaseName, interpolateParams, tlsOption)
119+
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?interpolateParams=%t&autocommit=true&charset=utf8mb4,utf8,latin1&tls=%s&allowNativePasswords=true", this.User, this.Password, hostname, this.Key.Port, databaseName, interpolateParams, tlsOption)
120120
}

0 commit comments

Comments
 (0)