Add code sample for use with existing MySQL client with multistatements=true

This commit is contained in:
Pavlina Drosos 2017-05-30 18:52:26 +03:00
parent 3682bcf9d2
commit b5c2f0f2bb
1 changed files with 30 additions and 1 deletions

View File

@ -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