This tool can be used to convert an existing MySQL database to a database which will run on a MySQL server which is running in strict mode.
Before running the generated queries, always backup your database! I'm not a Database Administrator (DBA), this tool is working for my specific needs. Besides that this is my first Golang project. I wrote this tool, because I needed to migrate multiple databases to run on a MySQL Strict server.
Please check out the LICENSE file, included in the source code.
- Table engines are InnoDB.
- MySQL Datetimes are not '0000-00-00 00:00:00'.
- MySQL Dates are not '0000-00-00'.
- Enum don't contain empty values.
# For help
$ mysql-to-strict --help
# Use tty for password.
$ mysql-to-strict --host=localhost --user=root --name=databasename
# Use password from shell (not recommended)
$ mysql-to-strict --host=localhost --user=root --password=pa$$w0rd --name=databasename
# It's also possible to use short flags.
$ mysql-to-strict -h localhost -u root -n databasename
# Forcing output of update queries.
$ mysql-to-strict --host=localhost --user=root --password=pa$$w0rd --name=databasename --force
If you do not want to compile the program yourself, you can use my prepaired Docker container.
docker run -it tomkeur/mysql-to-strict mysql-to-strict --host=localhost --user=root --name=databasename
Short | Long | Envvar | Description |
---|---|---|---|
-h | --host=HOST | MYSQL_HOST | Connect to host. ip:port or hostname:port. |
-u | --user=USER | MYSQL_USERNAME | User for login. |
-p | --password=PASSWORD | MYSQL_PASSWORD | Password to use when connecting to server. If password is not given it's asked from the tty. |
-n | --name=NAME | MYSQL_DATABASE | Database name. |
-f | --filename=NAME | FILENAME | Generated queries will be saved to this file. |
--force | Force running update queries, if your table structure is correct but your data is wrong. |
As you can see above: It's possible to use ENVIRONMENT variables, and even mix them up with CLI for example:
# Set environment variables
$ export MYSQL_HOST=mysql
$ export MYSQL_USERNAME=root
$ export MYSQL_PASSWORD=pa$$w0rd
# Run tool
$ mysql-to-strict -n databasename
Thanks for your interest in the project, and your willing to contribute:
- Pull requests are welcome!
- Please use
golangci-lint run
from github.com/golangci/golangci-lint for linting code.