Get the App
SLTechnology News&Howtos  ›  Database  › 

Docker mysql data is persisted locally, and the table name is large without distinction.

Shulou Source: shulou.com Published: 2022-06-01 14:34:34 09月15日 Update

Docker MySQL stores the data in a local directory, which is simple. You only need to map the local directory to the container.

1. Add the-v parameter

$docker run-d-e MYSQL_ROOT_PASSWORD=admin-- name mysql-v / data/mysql/data:/var/lib/mysql-p 3306 data/mysql/data:/var/lib/mysql 3306 mysql

You can also specify a profile

Docker run-d-e MYSQL_ROOT_PASSWORD=admin-- name mysql-v / data/mysql/my.cnf:/etc/mysql/my.cnf-v / data/mysql/data:/var/lib/mysql-p 3306 name mysql 3306 mysql

In this way, the configuration file can be modified, and the data can be stored in the local directory, killing two birds with one stone. The-v parameter can be used multiple times, one directory at a time. In this way, it is easy to configure.

Docker run-d-e MYSQL_ROOT_PASSWORD=admin-- name mysql-v / data/mysql/my.cnf:/etc/mysql/my.cnf-v / data/mysql/data:/var/lib/mysql-p 3306 name mysql-- lower_case_table_names=1

The explanation is as follows:

-d container runs in the background

-e MYSQL_ROOT_PASSWORD=admin configure the password for mysql root

-v map the configuration file and data storage path of mysql to the host, and persist the data

-p port mapping

-- name defines the name of the container

-- the lower_case_table_names=1 definition database is not case-sensitive

Steps for netizens:

Pull mysql image

Docker pull mysql

Run mysql

Docker run

-- net=host

-- restart=always

-- privileged=true

-v / usr/docker_dat/mysql/data:/var/lib/mysql

-- name mysql

-p 3306 Suzhou 3306

-e MYSQL_ROOT_PASSWORD=root

-v / etc/localtime:/etc/localtime:ro

-d mysql-- lower_case_table_names=1

3. Parameter description

-- restart=always starts with docker

-- privileged=true container root user has host root user rights

-v map the host path to the container

-e MYSQL_ROOT_PASSWORD=root sets the root user password

-d background start

-- lower_case_table_names=1 sets table names, parameter names, etc. to ignore case

-v / etc/localtime:/etc/localtime:ro sets the time of the container to synchronize with the host

Tags: Container data configuration parameters directory file user host background size host host password path storage run kill two birds with one stone name database method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Shulou Information macOS Docker