How to import mysql database using commandline

Sometimes you have to import large databases to mysql. So you are normally using phpmyadmin to import these databases. but issue is that it takes much time to be imported to mysql. On behalf of this time taken, you have to face phpmyadmin timeout error.

So you can not import large databases using phpmyadmin. In this tutorial, I am going to show you how to use windows/Linux Commandline to import large databases to mysql.


In Linux system, mysql command is already there. If you are a windows your, you can not directly use mysql commands. you have to go to the mysql installed directory and have to go to mysql/bin directory. After that you can issue mysql commands.

This is little bit a headace to me. So I have added mysql installed path to my path variables. Then I Can issue mysql commands from anywhere in the Windows System.

To add my sql installed directory to your path variable, Go to the mysql installed directory and find the bin directory. Copy the path and add the path to path variable in windows system. See the Image below.

(Add mysql path after the ; )
I have installed mysql in C:\xampp\mysql directory. So I added C:\xampp\mysql\bin line to path variable after the ; (semicolon)

Now you can Following Command to import your large database
mysql -u root -p database_name < database_file_name.sql


It prompts to enter mysql password. Enter password and press Enter key. It takes several minutes to complete the task.

Cheeers... !

0 comments:

Post a Comment

Ask anything about this Tutorial.