Skip to content

Instantly share code, notes, and snippets.

@wahidsadik
Created April 22, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wahidsadik/a44ff2b4b976a1ae557fcc51d3a8ce5c to your computer and use it in GitHub Desktop.
Save wahidsadik/a44ff2b4b976a1ae557fcc51d3a8ce5c to your computer and use it in GitHub Desktop.
How to export import MySQL data

Background

I am working on refactoring an existing PHP project to use a web-framework. As part of the project, I needed some data in my local MySQL instance. This led to me learnginb about the export/import operations.

Approach: Use CLI.

Doing it

SSH to the box that has the db.

Here is how to export the wbole schema:

  • $ mysqldump -d -u someuser -p mydatabase.
  • Provide password at the prompt.
  • Redirect ouput to a file as needed.

Here is how to export selective tables:

  • $ mysqldump -d -u someuser -p mydatabase table1 table2.
  • Provide password at the prompt.
  • Redirect ouput to a file as needed.

To export data as well, drop the -d switch.

Credit

This excellent tutorial: https://www.electrictoolbox.com/mysqldump-schema-only/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment