Using the mysqldump tool, you can back up a local database and restore it to a remote database with the same characteristics, all using a simple command. Next, you’ll see practical examples of using the mysqldump tool to export and import MySQL databases.
Below is an export example:
| |
And to import the database:
| |
Based on the syntax shown above, let’s say there is a database called “exemplo”, and we want to export it. To do this, we would run the following command:
| |
This command would export all the content in the “exemplo” database to a file called “exemplo.sql”.
Once we have our database exported, in another database (for example the one in the production environment) into which we want to import the previously exported database, we would run the following command:
| |
We can also import a database by connecting to mysql and running the source command there to import the database, for this we use the following sequence of commands:
| |
| |
| |
1. Back up N databases simultaneously:
If you intend to back up N databases simultaneously, first you’ll need to identify the names of the databases you want to export. To do this, you can connect to the database with the following command:
| |
After connecting, you can list the database names with the following command:

| |
The command’s output is shown below:
| |
If you want to export the cliente database and the exemplo database, you could run the tool using the following syntax:
| |
So our command would look like this:
| |
2. Back up all databases:
The following command would back up all databases:
| |
3. Back up a specific table
If you intend to back up a specific table within a database, you can use the following syntax:
| |
So if we wanted to export a table called “tabela1″ in a database called “exemplo”, we would use the following command:
| |
Well, that’s all folks.
Questions? Leave a comment!