Note that MySQL in docker exports databases and tables to local


Sometimes the MySQL data in docker may be inconvenient and intuitive to use. I want to copy down the database and use it on my computer. Now record the process.

1、 Export data in docker

1. Export the entire database
Mysqldump - U user name - P database name > exported file name
mysqldump -u dbuser -p dbname > dbname.sql
2. Export a table
Mysqldump - U user name - P database name table name > exported file name
mysqldump -u dbuser -p dbname users> dbname_users.sql
3. Export a database structure
mysqldump -u dbuser -p -d --add-drop-table dbname >d:/dbname_db.sql
-D no data -- add drop table add a drop table before each create statement
4. Import database
Common source commands
Enter the MySQL database console, such as
mysql -u root -p
MySQL > use database
Then use the source command, and the following parameters are script files (such as. SQL used here)
mysql>source d:/dbname.sql

Note: a permission denied error may occur. This is a permission problem. Enter the container with root:

docker exec -it -u root container——id bash

The export location is in the current folder

2、 Export from container to local machine

sudo docker cp 074af74c669d:/etc/bash.bashrc  /tmp
Or vice versa
sudo docker cp /tmp/index.html 074af74c669d:/etc/

That’s it

Recommended Today

Java Engineer Interview Questions

The content covers: Java, mybatis, zookeeper, Dubbo, elasticsearch, memcached, redis, mysql, spring, spring boot, springcloud, rabbitmq, Kafka, Linux, etcMybatis interview questions1. What is mybatis?1. Mybatis is a semi ORM (object relational mapping) framework. It encapsulates JDBC internally. During development, you only need to pay attention to the SQL statement itself, and you don’t need to […]