Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report