How to Take a Database Dump in MySQL Workbench

And use it to copy over or duplicate your database

A feature image consisting of ‘database dump’ as text, a toilet emoji and the MySQL Workbench icon. With a gradient background of pink to lilac.

A database dump is essentially a backup of a database — be it the structure of the database and/or the data held within it. It consists of a bunch of SQL commands which enable you to recreate your database from scratch.

Generating a database dump has multiple uses — such as in the event of data loss or if you wanted to rename a database (there seems to be no good way to do this in MySQL (╯°□°)╯︵ ┻━┻). For me, I wanted to be able to duplicate a database that we had running in our development environment so that I could have my own version and run everything locally 💯.

It is possible to create a database dump using a command line utility such as Mysqldump, though I’m currently using MySQL Workbench so I’m going to walk you through how to do this using said GUI.

Exporting data

Inside of the administration tab in MySQL Workbench, there are two headings that we’re going to make use of — ‘Data Export’ and ‘Data Import/Restore’. First let’s click into the ‘Data Export’ header to export the data/structure of the database.

The administration tab in MySQL Workbench with all the available headers underneath

Here we are shown the list of databases that we can export from. If this list isn’t accurate, try the ‘Refresh’ button. Once you have selected the database you want, you can control which tables you wish to export using the checkboxes.

The ‘Data Export’ page in MySQL Workbench

This page also allows you to select exactly what you wish to dump — be it the structure, or the data, or both. As I wish to copy over my database called ‘test’ to a new database, I’m going to leave this option as ‘Dump Structure and Data’.

Also on this screen you can select whether to export to a single ‘dump’ file or multiple files (in a ‘dump’ folder) — one for each table you’ve selected. I tend to leave this option as creating a single file. Once happy, click ‘Start Export’ and you’ll see the log of the export. Once this is completed, you can navigate to the path specified on the previous screen to view your dump file/folder.

Importing data

When you want to import your data/structure, head over to the ‘Data Import/Restore’ header. On this page, you are able to select the dump file/folder you wish to import.

The ‘Data Import’ page in MySQL Workbench

If you wish to create a new database to house your export, you can do so on this page by hitting the ‘New’ button. FYI: this database is created as soon as you hit ‘OK’ — not when the import is actually being carried out.

N.B. I found that when I was importing from a dump folder (not when using a single dump file), I had to change the database name found in a comment near the top of each file to reflect the name of the new database e.g.

— Host: localhost Database: newtest

This find and replace can be done easily on multiple files using a tool such as Atom — simply open up the project folder and hit Cmd+Shift+F to do a global find and replace.

Once happy, hit ‘Start Import’ and once again a log will be outputted. This could take some time depending on how much data there is to import.

After this is completed, click into your new database and marvel at the tables which have magically been copied over 😍

Originally published at https://www.madeleinesmith.uk.


How to Take a Database Dump in MySQL Workbench was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Madeleine Smith

And use it to copy over or duplicate your database

A feature image consisting of ‘database dump’ as text, a toilet emoji and the MySQL Workbench icon. With a gradient background of pink to lilac.

A database dump is essentially a backup of a database — be it the structure of the database and/or the data held within it. It consists of a bunch of SQL commands which enable you to recreate your database from scratch.

Generating a database dump has multiple uses — such as in the event of data loss or if you wanted to rename a database (there seems to be no good way to do this in MySQL (╯°□°)╯︵ ┻━┻). For me, I wanted to be able to duplicate a database that we had running in our development environment so that I could have my own version and run everything locally 💯.

It is possible to create a database dump using a command line utility such as Mysqldump, though I'm currently using MySQL Workbench so I'm going to walk you through how to do this using said GUI.

Exporting data

Inside of the administration tab in MySQL Workbench, there are two headings that we’re going to make use of — ‘Data Export’ and ‘Data Import/Restore’. First let’s click into the ‘Data Export’ header to export the data/structure of the database.

The administration tab in MySQL Workbench with all the available headers underneath

Here we are shown the list of databases that we can export from. If this list isn’t accurate, try the ‘Refresh’ button. Once you have selected the database you want, you can control which tables you wish to export using the checkboxes.

The ‘Data Export’ page in MySQL Workbench

This page also allows you to select exactly what you wish to dump — be it the structure, or the data, or both. As I wish to copy over my database called ‘test’ to a new database, I’m going to leave this option as ‘Dump Structure and Data’.

Also on this screen you can select whether to export to a single ‘dump’ file or multiple files (in a ‘dump’ folder) — one for each table you’ve selected. I tend to leave this option as creating a single file. Once happy, click ‘Start Export’ and you’ll see the log of the export. Once this is completed, you can navigate to the path specified on the previous screen to view your dump file/folder.

Importing data

When you want to import your data/structure, head over to the ‘Data Import/Restore’ header. On this page, you are able to select the dump file/folder you wish to import.

The ‘Data Import’ page in MySQL Workbench

If you wish to create a new database to house your export, you can do so on this page by hitting the ‘New’ button. FYI: this database is created as soon as you hit ‘OK’ — not when the import is actually being carried out.

N.B. I found that when I was importing from a dump folder (not when using a single dump file), I had to change the database name found in a comment near the top of each file to reflect the name of the new database e.g.
-- Host: localhost Database: newtest
This find and replace can be done easily on multiple files using a tool such as Atom — simply open up the project folder and hit Cmd+Shift+F to do a global find and replace.

Once happy, hit ‘Start Import’ and once again a log will be outputted. This could take some time depending on how much data there is to import.

After this is completed, click into your new database and marvel at the tables which have magically been copied over 😍

Originally published at https://www.madeleinesmith.uk.


How to Take a Database Dump in MySQL Workbench was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Madeleine Smith


Print Share Comment Cite Upload Translate Updates
APA

Madeleine Smith | Sciencx (2022-03-08T14:07:21+00:00) How to Take a Database Dump in MySQL Workbench. Retrieved from https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/

MLA
" » How to Take a Database Dump in MySQL Workbench." Madeleine Smith | Sciencx - Tuesday March 8, 2022, https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/
HARVARD
Madeleine Smith | Sciencx Tuesday March 8, 2022 » How to Take a Database Dump in MySQL Workbench., viewed ,<https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/>
VANCOUVER
Madeleine Smith | Sciencx - » How to Take a Database Dump in MySQL Workbench. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/
CHICAGO
" » How to Take a Database Dump in MySQL Workbench." Madeleine Smith | Sciencx - Accessed . https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/
IEEE
" » How to Take a Database Dump in MySQL Workbench." Madeleine Smith | Sciencx [Online]. Available: https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/. [Accessed: ]
rf:citation
» How to Take a Database Dump in MySQL Workbench | Madeleine Smith | Sciencx | https://www.scien.cx/2022/03/08/how-to-take-a-database-dump-in-mysql-workbench/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.