MySQL

How to Export MySQL Tables to a file from command line

Here we will see how to Export MySQL tables to a file from command line.

Export MySQL tables to a file:

mysqldump command helps us to export MySQL tables to a file.

1. Export Mysql Tables with table Data:

$ mysqldump -u [mysql_user] -p database_name > [file_path]fimename.sql

1.1 Example:

Terminal
$ mysqldump -u root -p otp > schema.sql

It asks you to enter the MySQL password, after successful authentication, it will export all the tables schema and data of otp database to a schema.sql file.

2. Export Mysql Tables without table Data:

If you wanted to export only table schemas without data so that you can use –no-data option.

Terminal
$ mysqldump -u root -p --no-data otp > schema.sql

3. Export Mysql table data without table schema:

It is also possible to export table data without table schema, using –no-create-info option.

Terminal
$ mysqldump -u root -p --no-create-info otp > schema.sql

4. Exporting selected tables schema:

We can ship the selected tables into a file.

$ mysqldump -u root -p otp t1,t2,t3.. > schema.sql

4.1 Example:

Terminal
$ mysqldump -u root -p otp department,employee > schema3.sql

5. Ignoring Some of the tables while exporting:

We can even overlook some of the tables while exporting entire schema into a single file using  –ignore-table.

Terminal
$ mysqldump -u root -p --ignore-table=otp.employee otp > schema.sql

The above command exports all the database tables except the employee table under the otp database into the schema.sql file.

6. Exporting remote server tables to local file:

You can invoke mysqldump locally against a remote server, for this the only thing you have to know remote server host address.

Terminal
$ mysqldump -h hostname_of_the_server -u root -p otp > schema.sql

References:

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Python

Python Insert data into MySQL Database

In this tutorial, we’ll show how to perform insert data into MySQL Database Python step by step. 1. Setup Required to connect MySQL To set up the environment,…

Python

Python MySQL create database and table

In this tutorial, we’ll show how to perform Create MySQL Database and insert some data init using Python step by step. 1. Setup Required to connect MySQL To…

Ask a question or leave a comment