How To Import and Export Database using the command line in MySQL

Importing and exporting databases is a common task in software development. You can use data dumps to back up and restore your information. You can also use them to migrate data to a new server or development environment.

Step 1 — Exporting a MySQL or MariaDB Database

The mysqldump console utility exports databases to SQL text files. This makes it easier to transfer and move databases. You will need your database’s name and credentials for an account whose privileges allow at least full read-only access to the database.

Use mysqldump to export your database:

mysqldump -u username -p database_name > data-dump.sql

    username  is the username you can log in to the database with
    database_name  is the name of the database to export
    data-dump.sql  is the file in the current directory that stores the output.

 

Step 2 — Importing a MySQL or MariaDB Database

To import an existing dump file into MySQL or MariaDB, you will have to create a new database. This database will hold the imported data.
 

mysql -u username -p new_database < data-dump.sql
 

 
    username is the username you can log in to the database with
    newdatabase is the name of the freshly created database
    data-dump.sql is the data dump file to be imported, located in the current directory


No comments:

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...