github.com/pupizoid/migrate@v3.5.4+incompatible/database/mysql/README.md (about) 1 # MySQL 2 3 `mysql://user:password@tcp(host:port)/dbname?query` 4 5 | URL Query | WithInstance Config | Description | 6 |------------|---------------------|-------------| 7 | `x-migrations-table` | `MigrationsTable` | Name of the migrations table | 8 | `dbname` | `DatabaseName` | The name of the database to connect to | 9 | `user` | | The user to sign in as | 10 | `password` | | The user's password | 11 | `host` | | The host to connect to. | 12 | `port` | | The port to bind to. | 13 | `tls` | | TLS / SSL encrypted connection parameter; see [go-sql-driver](https://github.com/go-sql-driver/mysql#tls). Use any name (e.g. `migrate`) if you want to use a custom TLS config (`x-tls-` queries). | 14 | `x-tls-ca` | | The location of the CA (certificate authority) file. | 15 | `x-tls-cert` | | The location of the client certicicate file. Must be used with `x-tls-key`. | 16 | `x-tls-key` | | The location of the private key file. Must be used with `x-tls-cert`. | 17 | `x-tls-insecure-skip-verify` | | Whether or not to use SSL (true\|false) | 18 19 ## Use with existing client 20 21 If you use the MySQL driver with existing database client, you must create the client with parameter `multiStatements=true`: 22 23 ```go 24 package main 25 26 import ( 27 "database/sql" 28 29 _ "github.com/go-sql-driver/mysql" 30 "github.com/golang-migrate/migrate" 31 "github.com/golang-migrate/migrate/database/mysql" 32 _ "github.com/golang-migrate/migrate/source/file" 33 ) 34 35 func main() { 36 db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname?multiStatements=true") 37 driver, _ := mysql.WithInstance(db, &mysql.Config{}) 38 m, _ := migrate.NewWithDatabaseInstance( 39 "file:///migrations", 40 "mysql", 41 driver, 42 ) 43 44 m.Steps(2) 45 } 46 ``` 47 48 ## Upgrading from v1 49 50 1. Write down the current migration version from schema_migrations 51 1. `DROP TABLE schema_migrations` 52 2. Wrap your existing migrations in transactions ([BEGIN/COMMIT](https://dev.mysql.com/doc/refman/5.7/en/commit.html)) if you use multiple statements within one migration. 53 3. Download and install the latest migrate version. 54 4. Force the current migration version with `migrate force <current_version>`.