Being exposed to the internet, your app is exposed to malicious attacks.

What Is mysqldump Used For?

The mysqldump tool has you covered for both the server compromise and migration situations.

Contents of a mysqldump File

Its basic function is to take a MySQL database and dump it out as a text file.

But not any text file; the file is a set of SQL statements.

In either case, the text file will be imported back into a MySQL database server.

Importing a mysqldump File into a New Database

It will execute all the SQL statements in the file, which rebuilds the database to its original state.

This part doesn’t use the mysqldump command, but it wouldn’t be possible without this utility either.

On macOS, see our directions toinstall MySQL on macOS 10.7(again, older but still applicable).

Comparing the Two Databases' Dump Files

This is a text file containing SQL statements.

you might open it in any text editor to inspect the contents.

Here’s at an export from a WordPress database that shows how these files are put together.

You should also have all the permissions for the database.

You don’t need the GRANT permission, but it’s easier to grant them all.

Learn permissionsbefore you change security roles within your database.

To re-import your data, log into the MySQL server with themysqlcommand.

Typeuse [database name]at the prompt, and substitute the name of the database.

Entersource [filename], and substitute the name of the dump file you took previously.

When you’re finished, a list of messages appears noting that SQL statements are executing.

Keep an eye out for errors, but if you have the right permissions, you should be fine.

When the process is complete, you’ll have a duplicate of the original database.

To verify the similarity between the databases, perform another dump then compare the two outputs.

Use a text editor ora dedicated diff toolto compare the two files.

The second is the timestamp for the dump file.

This is different because the second database was recreated after the first.

Otherwise, the files are exactly the same, meaning the databases that generated them are as well.

FAQ

Ask your database administrator to grant you the LOCK privilege.

Use a WHERE clause when creating a backup that only includes the rows fulfilling the given condition.