main body (of a book)
The server is using Docker to make notes about backing up and restoring the database:
Since docker is not an entity, the command to export the mysql database to the physical machine is as follows:
1: Check it outmysql run name (computing)
1 #docker ps
- 1
Results:
2: Backupdockercomprehensive database
- As you can see from the results of the first step, our mysql is running on a docker called mysql_server.
container. And the database we want to back up is in there, called test_db. mysql
The username and password are both root, and we back up the files to the /opt/sql_bak folder.
1 docker exec -it mysql_server [docker container name/ID】 mysqldump -uroot -p123456 [Database password] test_db [Database name]> /opt/sql_bak/test_db.sql [export table path
- 1
3: Import docker database
Method 1:
Buddhist teaching1:
1Import the file into the container first
2 #docker cp **.sql [container name]:/root/
3Entering the container
4 #docker exec -ti [container name/ID] sh
5Importing files into the database
6 # mysql -uroot -p [database name] < ***.sql
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
Method 2:
1 docker exec -i mysql_server [docker container name/ID] mysqltest_db_copy [database name]< /opt/sql_bak/test_db.sql [local data table path]
- 1
Note: You need to replace -it with -i, otherwise you will get an error: "the input device is not a TTY".