How to export and import MySQL data from a docker instance?

Beginner here, just have a basic MySQL database I’m setting up for use on my website.
Basically, I set up docker on one laptop and now I need to move it over to another (and I eventually also need to be able to export the MySQL database so I can upload it to my hosting provider). I can’t for the life of me get anything to work. When I’ve searched for how to do this, all I can find is this command:

docker exec CONTAINER_id /usr/bin/mysqldump -uusername --password=yourpassword databasename> backup.sql

I enter in the relevant details for my particular container and it throws an error that it can’t find mysqldump in the specified directory. I’ve looked long and hard on any other way to do this and nothing I’ve tried works. How would I go about doing this?

I don’t know what image you are using, so I can’t tell what is in it and what isn’t, but if it says mysqldump is not there, it is not there. If you have mysqldump on the host or any other container, you can connect to the mysql container from there. Or you can install a PHPMyAdmin or a MySQL WorkBench (at least I used that i the past) for dumping. Depending on how much data should be dumped.

But. if you will run the same container on the new machine, you could just copy the data on the volume. But don1t delete it from the odl machine until you confirmed it works on the new machine.

Thanks for the reply.
I did try exporting the data from Workbench. it threw an error saying that the MySQL version (11.something) was too new/unsupported and the export had errors in it, so I don’t want to rely on that. Confusing since I downloaded the latest version of workbench a week ago.

On exporting specific files - which ones? I found a directory that seems to correspond on the sql volume, but the file format isn’t recognized by workbench. Also related is that when I first installed docker, I had full access to the volumes in Windows Explorer via a “Linux” mount point, which had disappeared at some point and I can’t figure out how to re-enable.

Docker Desktop supports backing up volumes from the GUI. I’m not sure what you mean by “isn’t recognized by workbench”. Workbench doesn’t have to recognize mysql binary data. At least I don’t think so. A database stores files in specific folders. Normally you would easily access it on Linux, but Docker Desktop will run everything in a virtual machine. I’m not up to date regarding how the volumes can be seen from a WSL2 distribution, but you don’t have to rely on that. Use the volume backup feature of Docker Desktop on the Volumes tab. Choose a volume and select the “exports” tab. Then “Quick export”.

Docker Desktop can also browse the volumes

The warning from MySQL Workbench (latest version) is: “mysqldump.exe is version 8.0.38, but the MySQL Server to be dumped has version 11.5.2”. It then finishes the export with errors: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

I did try the Quick Export, but that also failed with an error that I can’t fully read because it is shown in a pop-up that doesn’t have enough space for the full error. At least - it did yesterday. For a reason I can’t fathom, I just tried it again so I could get the partial error to paste in (something related to a daemon) but today it worked! Nothing changed so I don’t know why it would work today but not yesterday. I tried all the standard troubleshooting yesterday (updated docker, restarted docker, restarted my computer, etc). I’ll see when I’m home later if I can re-import that backup into docker on my other laptop. Hopefully so.