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
Suddenly, I needed to build a private service for...
Syntax format: row_number() over(partition by gro...
CSS3 syntax: (1rem = 100px for a 750px design) @m...
1. Download mysql-8.0.17-winx64 from the official...
Preface Introduction Lombok is a handy tool, just...
This article shares with you the graphic tutorial...
I summarized the previous notes on installing MyS...
Port Mapping Before the Docker container is start...
Part.0 Background The company's intranet serv...
After setting up the MySQL master-slave, you ofte...
mistake The following error occurs when connectin...
1. Introduction First of all, we need to answer a...
This article example shares the specific code of ...
Table of contents Install and configure dnsmasq I...
The reason is this I wanted to deploy a mocker pl...