How to import SQL file to MySQL using Command Line

phpMyAdmin allows importing file to the selected MySQL database but it takes time to import according to the file size.

If a file is too large then it will give Timeout error if it exceeds the time.

With the use of the Command Line, you can easily import your SQL file in less time.

In this tutorial, I am using XAMPP in Windows.

How to import SQL file to MySQL using Command Line


Contents

  1. Create Database
  2. Copy SQL file
  3. Open Command Prompt
  4. Output
  5. Conclusion

1. Create Database

  • Open XAMPP and start Apache Server and MySQL Database.
  • First, need to create a database in MySQL.
  • Open phpMyAdmin and create a new database.
  • I have created a tutorial Database.

How to import SQL file to MySQL using Command Line


2. Copy SQL file

  • Copy your SQL file to xampp/mysql/bin/ directory.
  • I copied tutorial.sql file.

How to import SQL file to MySQL using Command Line


3. Open Command Prompt

  • Open Command Prompt.
  • Navigate to xampp/mysql/bin/ directory.

How to import SQL file to MySQL using Command Line

  • Type following command –

Syntax –

mysql -u username -p database_name < file.sql

username = Your MySQL username.

database_name = Database name in which you want to import.

file.sql = SQL file name.

Example –

mysql -u root -p tutorial < tutorial.sql
  • I am importing tutorial.sql file in tutorial Database.
  • Type the password if you have assigned to the user otherwise press Enter.

How to import SQL file to MySQL using Command Line


4. Output

  • Open phpMyAdmin and select the database to check tables imported or not.

How to import SQL file to MySQL using Command Line


5. Conclusion

Before executing import command first create your MySQL database using PHPMyAdmin and copy the SQL file in xampp/mysql/bin directory.

If you found this tutorial helpful then don't forget to share.

Related Post

Spread the love
  • 3
  •  
  •  
  •  
  •  
  •  

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *