Solve the problem of mysql data loss when docker restarts redis

Solve the problem of mysql data loss when docker restarts redis

Official documentation:

So mysql should be started as follows:

docker run -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=password -v /windows drive/specified folder path:/var/lib/mysql mysql:5.7

redis:

docker run -p 6379:6379 -d -v /windows drive/specified folder path:/data redis:5.0 redis-server --appendonly yes

Read more official documents, which contain detailed instructions

Additional knowledge: Docker mounts files into the container and does not change after modification, so it needs to be restarted

Today I found a very strange phenomenon. After I mounted the file on the host into docker, I deleted the file on the host and re-uploaded the file renamed to the same name, but the file in the container was not synchronized.

Let's talk about Linux first. Linux storage is divided into iNode and block. iNode stores the file's attribute information, such as size and location on the disk. Block is a 4k block that stores the actual information of the file. Files less than 4k in size will also occupy 4k of space.

After understanding the above, let's talk about docker. The file mounted into docker is actually an iNode remembered by docker. It can find the block, that is, the actual file information, through this iNode. If you use > to append redirection to write the file, it can be synchronized to docker. However, if you rename it with rm, the iNode of the file will change, but the iNode in docker still points to the previous disk location, so the file has not changed.

rm principle: rm only deletes the iNode. Without the iNode, the block on the disk cannot be found in the normal way. It looks like it has been deleted, but the file information is still there. The file information will be overwritten the next time it is written here. Therefore, there is a way to recover the deleted data. However, if the file is open when it is deleted, the file will not be deleted.

The same is true for vim. When you create a vim file, it copies the existing file. There will be a file at the same level directory that starts with . and ends with swp. When you save and exit, vim will delete the source file and rename this file to the name of the source file, and the iNode will naturally change.

The above article on solving the problem of mysql data loss when restarting redis in docker is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Spring Boot solves the problem of Redis cache + MySQL batch storage for high-concurrency data storage
  • How to ensure data consistency between MySQL and Redis
  • Python regularly extracts data from Mysql and stores it in Redis
  • Detailed explanation of the application case of hot and cold data exchange by combining PHP with Redis+MySQL
  • PHP's Laravel framework combined with MySQL and Redis database deployment
  • How to migrate a database from MySQL to Redis
  • How to connect Python to MySQL, MongoDB, Redis, memcache and other databases
  • Data consistency issues between MySQL and Redis

<<:  XHTML 1.0 Reference

>>:  SQL Server Comment Shortcut Key Operation

Recommend

How to Find the Execution Time of a Command or Process in Linux

On Unix-like systems, you may know when a command...

A brief discussion on the fun of :focus-within in CSS

I believe some people have seen this picture of c...

Detailed explanation of tinyMCE usage and experience

Detailed explanation of tinyMCE usage initializat...

Detailed explanation of CocosCreator optimization DrawCall

Table of contents Preface What is DrawCall How do...

Vue mobile terminal realizes finger sliding effect

This article example shares the specific code for...

HTML unordered list bullet points using images CSS writing

Create an HTML page with an unordered list of at l...

Nginx configures the same domain name to support both http and https access

Nginx is configured with the same domain name, wh...

Pay attention to the use of HTML tags in web page creation

This article introduces some issues about HTML ta...

Detailed explanation of Linux curl form login or submission and cookie usage

Preface This article mainly explains how to imple...

Mysql delete data and data table method example

It is very easy to delete data and tables in MySQ...

Solve the problem of setting Chinese language pack for Docker container

If you use docker search centos in Docker Use doc...

Disable IE Image Toolbar

I just tried it on IE6, and it does show the toolb...

How to use JavaScript to implement sorting algorithms

Table of contents Bubble Sort Selection Sort Inse...

Implementation of vue-nuxt login authentication

Table of contents introduce Link start Continue t...