An open API service indexing awesome lists of open source software.

https://github.com/asapdotid/docker-mysql

Custome from Bitnami project MySQL Server Community 5.7 & 8.0
https://github.com/asapdotid/docker-mysql

database docker docker-compose mysql mysql-database website

Last synced: 3 months ago
JSON representation

Custome from Bitnami project MySQL Server Community 5.7 & 8.0

Awesome Lists containing this project

README

          

# What is MySQL?

> MySQL is a fast, reliable, scalable, and easy to use open-source relational database system. MySQL Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.

[https://mysql.com/](https://mysql.com/)

# TL;DR;

# Custom Information

> Setting Timezone server every docker image os debian and orcle linux container to Asia/Jakarta

# Persisting your database

If you remove the container all your data will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.

For persistence you should mount a directory at the `/bitnami/mysql/data` path. If the mounted directory is empty, it will be initialized on the first run.

## Using Docker Compose

When not specified, Docker Compose automatically sets up a new network and attaches all deployed services to that network. However, we will explicitly define a new `bridge` network named `app-tier`. In this example we assume that you want to connect to the MySQL server from your own custom application image which is identified in the following snippet by the service name `myapp`.

```yaml
version: '2'

networks:
app-tier:
driver: bridge

services:
mysql:
image: 'bitnami/mysql:latest'
environment:
- ALLOW_EMPTY_PASSWORD=yes
networks:
- app-tier
myapp:
image: 'YOUR_APPLICATION_IMAGE'
networks:
- app-tier
```

> **IMPORTANT**:
>
> 1. Please update the `YOUR_APPLICATION_IMAGE` placeholder in the above snippet with your application image
> 2. In your application container, use the hostname `mysql` to connect to the MySQL server

Launch the containers using:

```bash
$ docker-compose up -d
```

# Configuration

## Initializing a new instance

When the container is executed for the first time, it will execute the files with extensions `.sh`, `.sql` and `.sql.gz` located at `/docker-entrypoint-initdb.d`.

In order to have your custom files inside the docker image you can mount them as a volume.

## Setting the root password on first run

The root user and password can easily be setup with the Bitnami MySQL Docker image using the following environment variables:

- `MYSQL_ROOT_USER`: The database admin user. Defaults to `root`.
- `MYSQL_ROOT_PASSWORD`: The database admin user password. No defaults.

Passing the `MYSQL_ROOT_PASSWORD` environment variable when running the image for the first time will set the password of the `MYSQL_ROOT_USER` user to the value of `MYSQL_ROOT_PASSWORD`.

```yaml
version: '2'

services:
mysql:
image: 'bitnami/mysql:latest'
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD=password123
```

**Warning** The `MYSQL_ROOT_USER` user is always created with remote access. It's suggested that the `MYSQL_ROOT_PASSWORD` env variable is always specified to set a password for the `MYSQL_ROOT_USER` user. In case you want to allow the `MYSQL_ROOT_USER` user to access the database without a password set the environment variable `ALLOW_EMPTY_PASSWORD=yes`. **This is recommended only for development**.

## Allowing empty passwords

By default the MySQL image expects all the available passwords to be set. In order to allow empty passwords, it is necessary to set the `ALLOW_EMPTY_PASSWORD=yes` env variable. This env variable is only recommended for testing or development purposes. We strongly recommend specifying the `MYSQL_ROOT_PASSWORD` for any other scenario.

```yaml
version: '2'

services:
mysql:
image: 'bitnami/mysql:latest'
ports:
- '3306:3306'
environment:
- ALLOW_EMPTY_PASSWORD=yes
```

## Creating a database on first run

By passing the `MYSQL_DATABASE` environment variable when running the image for the first time, a database will be created. This is useful if your application requires that a database already exists, saving you from having to manually create the database using the MySQL client.

```yaml
version: '2'

services:
mysql:
image: 'bitnami/mysql:latest'
ports:
- '3306:3306'
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=my_database
```

## Creating a database user on first run

You can create a restricted database user that only has permissions for the database created with the [`MYSQL_DATABASE`](#creating-a-database-on-first-run) environment variable. To do this, provide the `MYSQL_USER` environment variable and to set a password for the database user provide the `MYSQL_PASSWORD` variable.

```yaml
version: '2'

services:
mysql:
image: 'bitnami/mysql:latest'
ports:
- '3306:3306'
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MYSQL_USER=my_user
- MYSQL_PASSWORD=my_password
- MYSQL_DATABASE=my_database
```

**Note!** The `root` user will be created with remote access and without a password if `ALLOW_EMPTY_PASSWORD` is enabled. Please provide the `MYSQL_ROOT_PASSWORD` env variable instead if you want to set a password for the `root` user.