From b5c2f0f2bb50eb62537062b486ce37bb78f33293 Mon Sep 17 00:00:00 2001 From: Pavlina Drosos Date: Tue, 30 May 2017 18:52:26 +0300 Subject: [PATCH] Add code sample for use with existing MySQL client with multistatements=true --- database/mysql/README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/database/mysql/README.md b/database/mysql/README.md index fc79c98..490e90b 100644 --- a/database/mysql/README.md +++ b/database/mysql/README.md @@ -1,4 +1,4 @@ -# mysql +# MySQL `mysql://user:password@tcp(host:port)/dbname?query` @@ -15,6 +15,35 @@ | `x-tls-key` | | Key file location. | | `x-tls-insecure-skip-verify` | | Whether or not to use SSL (true\|false) | +## Use with existing client + +If you use the MySQL driver with existing database client, you must create the client with parameter `multiStatements=true`: + +```go +package main + +import ( + "database/sql" + + _ "github.com/go-sql-driver/mysql" + "github.com/mattes/migrate" + "github.com/mattes/migrate/database/mysql" + _ "github.com/mattes/migrate/source/file" +) + +func main() { + db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname?multiStatements=true") + driver, _ := mysql.WithInstance(db, &mysql.Config{}) + m, _ := migrate.NewWithDatabaseInstance( + "file:///migrations", + "mysql", + driver, + ) + + m.Steps(2) +} +``` + ## Upgrading from v1 1. Write down the current migration version from schema_migrations