github.com/matcornic/migrate@v3.3.2-0.20180717234201-feea45c20506+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  | `x-tls-ca` | | The location of the root certificate file. |
    14  | `x-tls-cert` | | Cert file location. |
    15  | `x-tls-key` | | Key file location. | 
    16  | `x-tls-insecure-skip-verify` | | Whether or not to use SSL (true\|false) | 
    17  
    18  ## Use with existing client
    19  
    20  If you use the MySQL driver with existing database client, you must create the client with parameter `multiStatements=true`:
    21  
    22  ```go
    23  package main
    24  
    25  import (
    26      "database/sql"
    27      
    28      _ "github.com/go-sql-driver/mysql"
    29      "github.com/golang-migrate/migrate"
    30      "github.com/golang-migrate/migrate/database/mysql"
    31      _ "github.com/golang-migrate/migrate/source/file"
    32  )
    33  
    34  func main() {
    35      db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname?multiStatements=true")
    36      driver, _ := mysql.WithInstance(db, &mysql.Config{})
    37      m, _ := migrate.NewWithDatabaseInstance(
    38          "file:///migrations",
    39          "mysql", 
    40          driver,
    41      )
    42      
    43      m.Steps(2)
    44  }
    45  ```
    46  
    47  ## Upgrading from v1
    48  
    49  1. Write down the current migration version from schema_migrations
    50  1. `DROP TABLE schema_migrations`
    51  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.
    52  3. Download and install the latest migrate version.
    53  4. Force the current migration version with `migrate force <current_version>`.