Exporting MySQL Data Using Command Line: A Comprehensive Guide

on Data Warehouse, ETL, Tutorials • June 24th, 2020 • Write for Hevo

Are you facing difficulties with your daily MySQL data exports? Do you find it gruelling 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

Introduction To MySQL

mysql export database command line

MySQL is an open-source database management system that is distributed, supported and developed by Oracle Incorporation (INC). MySQL is a relational database which 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.

Need To 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 backup (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.

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 mysqldump utility.

Method 3: Using Hevo Data, The Easier Approach

Hevo Data provides a hassle-free & a 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 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.

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.

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 which provides a secure way to access both 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 using the 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. 

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

Enter the database password to start exporting data 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 commmand:

$ 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:

  • It is exceptionally fast.
  • Using SSH (Secure Shell) makes the process completely reliable.
  • It works perfectly on databases of all sizes without compromising on the 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 exporting data which can be challenging for users who are not comfortable with coding.
  • In a real-life scenario, this method requires allocating a good number of human resources for both the development and maintenance of such pipelines to ensure consistent, day-to-day operations.

Method 3: Using Hevo Data, The Easier Approach

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 a matter of 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.

Check out what makes Hevo amazing:

  1. Simplicity: Exporting data from MySQL might get tricky. Hevo truly abstracts the complexity & helps you carry out the export in a jiff.
  2. Huge Source Platform Support: Hevo can help you bring in data from 100’s of sources thereby making it the ideal partner for your business’s growing data needs.
  3. Interactive UI: The Hevo platform can be set up in just a few minutes. Owing to its minimal learning curve, users can straightaway perform their desired operations instead of spending hours learning the platform.
  4. Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
  5. 24*7 Customer Support: The Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support call.
  6. Schema Management: Hevo takes away the tedious task of schema management & automatically detects schema of incoming objects.

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 here for a 14-day free trial & experience the true seamless way to manage your daily data needs.

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

No-code Data Pipeline For MySQL