How to Export and Import a MySQL Database Using Command Line

How to Export and Import a MySQL Database Using Command Line

Having an up-to-date backup of your database is essential to protect your critical information and ensure business continuity. In this tutorial, we will show you how to export a database using the command line.
Info
It is important to perform a complete backup of the database before any procedure

Exporting the MySQL database

Open a terminal or command line on your operating system and run the following command to export the database:
  1. mysqldump -u [usuario] -p [base_de_datos] > [ruta_del_archivo.sql]
The command will run and export the database in SQL format to the specified file.

Importing the MySQL database 

Run the following command to import the database:
  1. mysql -u [usuario] -p [base_de_datos] < [ruta_del_archivo.sql]
 
Remember that this tutorial is a general example and the commands may vary depending on the database management system you are using. Make sure to adjust the commands and parameters according to your specific needs and configuration.
    • Related Articles

    • Fix MySQL Stored Procedures Import Error in cPanel

      When working with MySQL databases that include stored procedures, it's common to encounter errors during import in shared hosting environments with cPanel. These errors are usually related to the DEFINER parameter, which specifies the owner of the ...
    • How to change File Permissions and Ownership via Command Line

      Files and folders with incorrect permissions or ownership can be vulnerable to unauthorized access, potentially compromising the integrity of your data and the security of your website. Additionally, these issues can cause read, write, or execution ...
    • How to Block and Manage IPs in CSF via Command Line

      CSF (ConfigServer Security & Firewall) is one of the most widely used firewalls on servers running cPanel/WHM. It allows advanced server access management, blocking or allowing IP addresses from the command line. In this article, you will learn how ...
    • Using Screen on Linux: create, resume, and close terminal sessions

      Screen is a command-line tool on Linux that allows you to manage multiple, persistent terminal sessions. With screen, you can run programs in the background, detach from a session without closing it, and resume it later. This is useful for ...
    • JetBackup 5: How to fix the Integrity Check error using CLI/SSH

      When JetBackup performs its automated integrity verification processes, they may sometimes complete partially due to network interruptions, timeouts, or communication issues with the remote storage destination. If you receive notifications indicating ...