Import - Export MySQL / MariaDB database using the terminal in Ubuntu Linux

<< More Tips   |   Added On: 15/12/15   |    Category: Linux    |    Number of Views: 666

Tweet

To Export your database using the terminal, in Ubuntu enter the following command:-

mysqldump -u {database_username} -p {database_name} > mysqlbackup.sql

You will be prompted for your MySQL password. Your database will then be downloaded.

To Import your database using the terminal in Ubuntu enter the following command:-
mysql -u {database_username} -p {database_name} < mysqlbackup.sql

You will be prompted for your MySQL password. Your database will then be imported.

Other ways to import and export MySQL:-
There are other ways to Import and Export your database using PHPMyAdmin.
This is fine for small imports and exports but most webhosts impose a 2MB limit on imports.

Using PHPMyAdmin on a live busy site, may also lock all the tables whilst importing or exporting the databases. It also takes longer to import and export using this method.

PHPMyAdmin's strengths are it's ease of use when creating new databases, tables and fields. This can be done directly through your webbrowser, without the need to use the terminal.