- export data
- Check the mysql running name
docker ps
result:

- Execute the export (backup) database command:
From the results of the first step, we can see that our mysql is running in a docker container called mysql_server. And the database we want to back up is in it, called test_db. The username and password of mysql are both root, and we back up the files to the host /opt/sql_bak folder.
docker exec -it slave mysqldump -uroot -proot db2 > /home/zcl/dbsql/db2.sql
- Import Data
- Copy the data sql on the host to the file of the container----because it is -v to start the file structure directory is consistent
- docker cp /opt/gysql.sql gysql (container name):/opt/gysql.sql
- Enter the container--->docker exec -it gysql (container name) bash
- Log in to the mysql database in the container------"mysql -uroot -p123456
- Create database of objects create database somp;
- Use use somp ---> execute source /opt/gysql.sql
- exit;
Data import and export of mysql database in docker
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324929920&siteId=291194637
Recommended
Ranking