Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f50dcf8
commit cde72cc
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,61 @@ | ||
# MySQL | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Postgres module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/mysql | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a MySQL container](../../modules/mysql/mysql.go) | ||
<!--/codeinclude--> | ||
|
||
## Module Reference | ||
|
||
The MySQL module exposes one entrypoint function to create the container, and this function receives three parameters: | ||
|
||
```golang | ||
func StartContainer(ctx context.Context, image string, opts ...Option) (*MySQLContainer, error) { | ||
``` | ||
- `context.Context`, the Go context. | ||
- `image`, the image to use for the container. | ||
- `Option`, a variad argument for passing options. | ||
## Container Options | ||
When starting the MySQL container, you can pass options in a variadic way to configure it. | ||
!!!tip | ||
You can find all the available configuration and environment variables for the MySQL Docker image on [Docker Hub](https://hub.docker.com/_/mysql). | ||
### Set username, password and database name | ||
If you need to set a different database, and its credentials, you can use `WithUsername`, `WithPassword`, `WithDatabase` | ||
options. By default, the username, the password and the database name is `test`. | ||
<!--codeinclude--> | ||
[Custom Database initialization](../../modules/mysql/mysql_test.go) inside_block:customInitialization | ||
<!--/codeinclude--> | ||
### Init Scripts | ||
If you would like to perform DDL or DML operations in the MySQL container, add one or more `*.sql`, `*.sql.gz`, or `*.sh` | ||
scripts to the container request. Those files will be copied under `/docker-entrypoint-initdb.d`. | ||
<!--codeinclude--> | ||
[Include init scripts](../../modules/mysql/mysql_test.go) inside_block:withScripts | ||
<!--/codeinclude--> | ||
### Custom configuration | ||
If you need to set a custom configuration, you can use `WithConfigFile` option. | ||
<!--codeinclude--> | ||
[Test for a MySQL container](../../modules/mysql/mysql_test.go) | ||
[Custom MySQL config file](../../modules/mysql/mysql_test.go) inside_block:withConfigFile | ||
<!--/codeinclude--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters