How to Import Database in MySQL Using Command Line

Share this Article
Reading Time: 3 minutes
340 Views

Inside this article we will see how to import database in mysql using command line in ubuntu operating system. Tutorial will be super easy to understand.

When you have a large size of database then we can not easily import from phpmyadmin manual interface. So in that case we need to use mysql commands for it. Here, we will see a simple command to import large size database in mysql using command in ubuntu.

We can import databases in mysql in several ways. But in this tutorial we will use a command which will be executed from terminal in ubuntu to import.

Learn More –

Let’s get started.


Manual PhpMyAdmin Interface For Import

As we have two options available to import data in MySQL. Options are –

  • Manual Interface of PhpMyAdmin
  • Using Command Line of MySQL

Import Data To MySQL

Inside this import page we have several settings available about import database to mysql.

But if we have large size database or say import manual tool is not working then in these cases we can use command line.


MySQL Import Database via Interactive Mode

Inside this case we are going to use terminal and few commands of mysql to use MySQL interactive mode.

Also here, we have multiple options to choose file formats for import . We will use .sql to understand.

Import data to MySQL Table

Syntax:

$ mysql -u {username} -p {database_name} < {file_path}

Example:

$ mysql -u root -p db_management < /var/www/html/dbt/data.sql

When you press enter you need to pass password and then data will be automatically import to your selected database.

data.sql file will be imported to db_management database. /var/www/html/dbt/data.sql is file path.

We hope this article helped you to learn about How to Import Database in MySQL Using Command Line in Ubuntu in a very detailed way.

Buy Me a Coffee

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Learn More on MySQL