How To Export MySQL Database Command Line? : 3 Easy Methods

on Data Warehouse, ETL, Tutorials • January 7th, 2022 • Write for Hevo

MySQL Export Database Command Line

Are you facing difficulties with your daily MySQL data exports? Do you find it grueling to perform all the work? Well, look no further! This article will answer all your queries & relieve you of the stress of finding a truly efficient solution. Follow our easy step-by-step solution to help you master the skill to efficiently export your data from MySQL in your preferred format via MySQL export database command Line & various other methods.

Upon a complete walkthrough of the content, you will be able to carry out a successful data export to the data warehouse/any other destination of your choice for a fruitful analysis.

Table of Contents

What is MySQL?

MySQL Logo: MySQL Export Database Command Line
Image Source: Logo Wine

MySQL is an open-source database management system that is distributed, supported and developed by Oracle Incorporation (INC). MySQL is a relational database that stores the data in the form of tables and views. It supports various database objects such as tables, stored procedures, functions, triggers, views, indexes, and even cursors.

MySQL database server runs comfortably on any laptop or desktop even with various web applications or servers installed on the system. MySQL database server is designed to support large databases which may contain data of many organizations. MySQL database servers support a wide range of functions and multiple web API’s.

It performs exceptionally well & securely accesses various databases on the internet. It ensures connectivity with servers and devices at all times.

For further information, you can check the official MySQL site here.

Why Should You Export a MySQL Database?

Exporting the MySQL database is advantageous for the backup and restoration process. The restoration process helps to recover back data in the event of an emergency making use of the backup. The export functionality further helps in transferring data from one server to another.

By exporting the MySQL database, you can create partial backups (backups of specific tables or schemas), incremental backups (backup of the changes made to prior backup), compressed backups (reducing the space requirements up to 80%). You can even export the data in various formats like JSON, XML, CSV, and HTML.

Download the Ultimate Guide on Database Replication
Download the Ultimate Guide on Database Replication
Download the Ultimate Guide on Database Replication
Learn the 3 ways to replicate databases & which one you should prefer.

Ways To Export Data From MySQL

Three popular methods that can be used to export data are:

Method 1: Using phpMyAdmin

It is a utility created and developed to manage web servers. In this tool, you can run MySQL queries, change collations, optimize the queries and execute many MySQL commands. phpMyAdmin is one of the most popularly used tools to export the MySQL database.

Method 2: Using MySQL Export Database Command Line

Command-line is an efficient yet slightly complex way to export the MySQL database. It is suitable for both small and large databases. It requires the users to write some custom codes to export data using the mysqldump.

Method 3: Using Hevo Data, The Easier Approach

Hevo Data provides a hassle-free & fully managed solution using its No-code Data Pipelines. It helps you export the data effortlessly from MySQL without any intervention. Hevo’s pre-built integration with MySQL (among 100+ Sources) will take full charge of the data export process, allowing you to focus on key business activities.

Start the 14-day free trial now.

Prerequisites

  • Working knowledge of MySQL.
  • MySQL installed at host workstation.
  • Working knowledge of MySQL Shell.
  • Pre-configured phpMyAdmin account.
  • A general idea of CSV & JSON file structure.

Two Approaches for Exporting a MySQL Database

There are two main approaches to export data from a MySQL database:

Approach 1: Table Data Export

The table data export wizard helps to export the MySQL data in JSON and CSV file formats. You can export data using column selections, datatypes selection, encodings and even separators & it can be performed either locally or on remote servers. MySQL workbench tool can be used to export the data from the table.

  • Open the MySQL database wizard & select the table you want to export. Right-click on the table name & select the table data export wizard option.
  • In the table data export tab, you can select a particular column or an entire table to export.
  • Now provide a specific location where you want to export the data to & your desired file format. Users can choose between CSV and JSON.
  • Click on the next option to start the process & you can even monitor the progress simultaneously.

Approach 2: Result Data Export

The result set obtained by running a query can be exported in JSON, CSV, HTML, and XML file format using this method.

  • Run the query on a MySQL database. This will generate an output in a grid format.
  • Select the output of the query & click on the export/import option. Now provide a file name along with the format you want to export the data in.
Selecting the data export type: MySQL Export Database Command Line
Image Source: MySQL Developer Zone

Hevo, A Simpler Alternative to Integrate your Data for Analysis

Hevo offers a faster way to move data from databases or SaaS applications into your data warehouse to be visualized in a BI tool. Hevo is fully automated and hence does not require you to code.

Get Started with Hevo for Free

Check out some of the cool features of Hevo:

  • Completely Automated: The Hevo platform can be set up in just a few minutes and requires minimal maintenance.
  • Real-time Data Transfer: Hevo provides real-time data migration, so you can have analysis-ready data always.
  • 100% Complete & Accurate Data Transfer: Hevo’s robust infrastructure ensures reliable data transfer with zero data loss.
  • Scalable Infrastructure: Hevo has in-built integrations for 100+ sources that can help you scale your data infrastructure as required.
  • 24/7 Live Support: The Hevo team is available round the clock to extend exceptional support to you through chat, email, and support call.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!

Methods to Export a MySQL Database

There are various methods to export data from MySQL database:

Method 1: Using phpMyAdmin

It is a utility created and developed to manage web servers. In this tool, you can run MySQL queries, change collations, optimize the queries and execute many MySQL commands. phpMyAdmin is one of the most popularly used tools to export the MySQL database.

You can use the following steps to perform a MySQL data export using the phpMyAdmin tool:

Step 1: Logging in to cPanel

Log in to cPanel & select the phpMyAdmin option from the databases section.

Select the database you want to export and click on the Export tab.

Signing in to cPanel: MySQL Export Database Command Line
Image Source: MySQL Developer Zone

Step 2: Exporting Using cPanel

In the export tab, you can select a particular column or an entire table to export. To select the entire database, use the select all option.

Once you have selected the desired columns, click on the save as file checkbox and set the compression type to zipped. This will reduce the file size and make the export process much more efficient.

Now click on the go button to export the file to your system.

For further information on phpMyAdmin, you can check the official documentation here.

Method 2: Using MySQL Export Database Command Line

Command line is an efficient yet slightly complex way to export the MySQL database. It is suitable for both small and large databases. It requires the users to write some custom codes to export data using mysqldump utility.

SSH (Secure Shell) is a Unix-based command line interface that provides a secure way to access local and remote computers. SSH makes use of Linux commands but it can be used on Windows & MAC OS as well. These commands are highly secure as it authenticates both server & client machines using certificates and uses passwords in an encrypted manner.

You can use the following steps to perform a MySQL Export Database Command Line:

Step 1: Logging in to the Server

You can use the following command to login via SSH:

ssh root @ouripaddress

Keep the username as root, this improves readability as you need to log in as a root user. Ensure that you have entered the correct IP address and press enter to proceed.

ssh root 123.123.123.123 # Here 123.123.123.123 is an example IP address. 
mysql export database command line: MySQL Export Database Command Line

Now enter the password to establish the connection.

Step 2: Using the Command Prompt

Open the command prompt and use the cd command as follows to navigate to the directory for which the user has the write access:

cd /hp/hhh/MYSQLDB.com/tables # Here you need to specify the path after cd.

Step 3: Exporting the Database

Use the mysqldump utility to export the database. The command is used as follows:

$ mysqldump -u USER_NAME -p DB_NAME >file_name.format

The user needs to specify the file name & the desired format in which they want to export the data.

Example query: Here tutorial.sql is the file name.

$ mysqldump -u root -p tutorial >tutorial.sql
Starting xampp mysql: MySQL Export Database Command Line

Enter the database password to start MySQL export Database Command Line into the mentioned file. Now connect to the server using FTP and navigate to the directory to download the exported data file.

You can modify the mysqldump utility to meet your requirements as follows:

a) To export a specific table, you can use the following command:

$ mysqldump -u USER_NAME -p DB_NAME table1 table2 > file_name

b) To export multiple databases, you can use the following command:

$ mysqldump -u USER_NAME -p ---databases DB_NAME1 DB_Name2 DB_Name3> file_name

c) To prevent a table from being exported, use the following command:

$ mysqldump -u USER_NAME -p DB_NAME --ignore-table=DB_NAME.TABLE_NAME > file_name

This is how you can perform the MySQL export database command line method.

Advantages of Using MySQL Export Database Command Line Method:

  • MySQL Export Database Command Line is exceptionally fast.
  • Using SSH (Secure Shell) makes the process completely reliable.
  • MySQL Export Database Command Line method works perfectly on databases of all sizes without compromising on performance.
  • Access to a remote web server is not required.

Limitations of Using MySQL Export Database Command Line Method:

  • SSH access is a must.
  • The mysqldump utility often locks out users for a long period when it’s used with large databases.
  • Users need to repeatedly write the code for MySQL Export Database Command Line which can be challenging for users who are not comfortable with coding.
  • In a real-life scenario, MySQL Export Database Command Line method requires allocating a good number of human resources to develop and maintain such pipelines to ensure consistent, day-to-day operations.

Method 3: Using Hevo Data, the Easier Approach

Hevo Data Logo: MySQL Export Database Command Line

A fully managed, No-Code Data Pipeline platform like Hevo Data, can help you export data from MySQL (among 100+ Sources) to your desired destination in real-time, in an effortless manner. Hevo with its minimal learning curve can be set up in minutes, making the user ready to perform operations in no time. It is the users’ delight and provides a fully managed & automated solution to export data to any destination without any hassle.

Visit our Website to Explore Hevo

Conclusion

This article teaches you how to successfully perform the MySQL export database command-line method. It provides a step-by-step guide to help you grasp the complete concept behind each step and efficiently implement them. It further introduces an alternative method, Hevo Data, a No-Code Data Pipeline, that will help you export data from MySQL without having to write any code. It is reliable, consistent, and ensures data is exported securely with its end-to-end encryption & two-factor authentication.

Want to take Hevo for a spin?

Sign Up for a 14 day free trial & experience the true seamless way to manage your daily data needs.

Let us know about your experience using the MySQL export database command line method in the comment section below.

No-code Data Pipeline For MySQL