Data import and export of mysql database in docker

  1. export data
  2. Check the mysql running name
    docker ps
    

    result:

    docker_ps

  3. 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
  4. Import Data
  5. 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
  6. docker cp /opt/gysql.sql gysql (container name):/opt/gysql.sql  
  7. Enter the container--->docker exec -it gysql (container name) bash
  8. Log in to the mysql database in the container------"mysql -uroot -p123456
  9. Create database of objects create database somp;
  10. Use use somp ---> execute source /opt/gysql.sql
  11. exit;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324929920&siteId=291194637