Import / export mysql or maria database using linux terminal

Category : MySQL

Following tutorial helps in exporting or importing MySQL / MariaDB database using terminal commands. It is very useful when the database size is pretty big and the software like PHPMyAdmin , MySQL workbench might give you timeout issue or take abnormally very high time.

Using the following method is a direct interaction with the MySQL server and hence the fastest way out for export or import of database.

Prerequisites

To import and/or export a MySQL or MariaDB database, you will need:

  • Access to the Linux server terminal
  • The database name, user, and password of it

Exporting the Database

mysqldump is a powerful tool which is used to export the MySQL or maria database.

Export the database using the following command :

mysqldump -u username -p database_name > filename.sql

  • username is the user assigned to the database
  • database_name is the name of the database that will be exported
  • filename.sql is the file in the current directory that the output will be saved to

Importing the Database

You can import any SQL or compressed database backup file (.zip) by using the following command :

mysql -u username -p database_name < filename.sql

The command will not print any output. If your backup file is large, you need to wait a bit for it to execute all the queries of the file. Stay patient and wait for the command to finish.

Read more on mysql here : https://www.basezap.com/category/mysql/