Preface We all know that the import and export of MySQL data can be solved with a mysqldump command, but what if MySQL is running in a docker environment? The solution is to use the mysqldump command, but we need to enter the mysql container of docker to execute it, and configure volumes so that the exported data files can be copied to the host machine's disk. So the operation steps can be divided into:
As for data import, it is too simple to explain. Let's first look at the common options of the mysqldump command:
Configuring volumes First, I use docker-compose to arrange the docker containers. For the complete configuration code, please see this project: liumapp/rabbitmq-mysql-redis-in-docker Please note the following lines in the docker-compose.yml configuration file of this project: mysql: container_name: mysql image:mysql:5.5.60 restart: always volumes: - ./mysql/data:/var/lib/mysql - ./mysql/conf/mysqld.conf:/etc/mysql/mysql.conf.d/mysqld.cnf The volumes I configured for the mysql container are to map the project's mysql/data directory to the /var/lib/mysql in the docker container. So when I enter the mysql container of docker and execute the export command, I only need to export the data in the /var/lib/mysql/ directory, and I can find the corresponding data file in the ./mysql/data/ directory of the host machine. Enter the container to export data First execute docker ps Find the name of the mysql container Then execute docker exec -it mysql /bin/bash Entering the container Execute Command whereis mysql Find the running path of mysql, here is: /usr/local/mysql/bin, enter it with cd cd /usr/local/mysql/bin Please note that the path here refers to the path inside the Docker container and has nothing to do with your host path. Execute the export command mysqldump -u username -p database name> save file .sql After entering the password, the export is basically successful. Please note that the path to save the file should be set under volumes, that is, /var/lib/mysql/ Then enter exit Exit the container and return to the host machine, we can find the exported data file If you want to export in csv format, change the mysqldump command to: mysql -u username --password=password --database=database name --execute='SELECT `FIELD`, `FIELD` FROM `TABLE` LIMIT 0, 10000 ' -X > Save file.sql You can Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: jQuery realizes the shuttle box effect
>>: MySQL 5.7.17 installation and configuration tutorial for Mac
Preface We all know that in Linux, "everythi...
The span tag is often used when making HTML web p...
First, let's take a look at the relative leng...
Record the BUG that got me stuck all afternoon to...
MySQL is divided into installation version and fr...
1. Download 1. Click the latest download from the...
Table of contents Docker Basic Concepts Docker in...
The database queries which object contains which ...
1 Download and start Tomcat Go to the official we...
Error message: Store update, insert, or delete st...
Find the problem When retrieving the top SQL stat...
This article records the detailed process of down...
During the crawler development process, you must ...
Awk is an application for processing text files, ...
Preface Today I encountered a very strange proble...