Import MySQL Database in Local Computer by Command line and User Interface [XAMPP]

In this tutorial, I am going to share with you how to import MySQL database in the local computer by using the Command-line interface and by using the User interface? In this tutorial, I am using XAMPP Package for Apache and MySQL.

MySQL is one of the best and easy to learn database because its interface is very simple and all institutes give training on this database because it is totally free. It is the best database mainly for beginners because they don’t need to store more data on the database. They need only to learn simple CRUD (Create, Read, Update and Delete) operation on the database.

When we execute a project with MySQL database on another computer then we need to import a database of that project in MySQL to run the complete project.

Import and export are two basic features of the database when we move projects from one computer to another computer or one server to another server then we need to move the database also with that project. Exporting the database means keep backup of that database or moving that database to another computer by creating a backup file and Importing the database means to store or implement that database in their respective folders or place to execute the project.

Let’s see the importing process of MySQL database in the local computer by both methods one by one.

Video Tutorial: Click here to see video tutorial

Steps to Import MySQL database by User Interface

Importing the database by user interface is very easy for beginners as well as professionals because most of the users don’t want to remember commands.

In this section, I will tell you to create database in MySQL first and then import database by import section.

Here, I am using the XAMPP package to execute PHP and MySQL. Most of the users use the XAMPP package because it is available for all operating systems. It also provides Apache server, MySQL and many more tools.

If you have installed the XAMPP then first start Apache and MySQL and go to the browser. After that, open database user interface by typing “localhost/phpmyadmin” in the browser address bar.

Now you can see a simple User interface of phpMyAdmin. It is a free and open-source administrator tool for MySQL and MariaDB. In this interface, you can see a “New” option at the top left. By clicking on the “New” option you can create a new database. You can see the steps in the below image.

Create new database in MySQL

You can also create a database by SQL command “CREATE DATABASE database_name

To import the database in MySQL, you must have already created a database in MySQL. If you don’t have then you can create by above explanation and if you have already then followed the below steps:

  • First, open that database in which you want to import database files.
  • Go to the import section by clicking on the “Import” tab.
  • Now you will be able to see a choose file option. Here, you can select your SQL file but before selecting your file, you can create a ZIP file of that SQL file for fast processing. If you have a small size database then you can do the process without creating a ZIP file. The ZIP file extension should be but it is not mandatory.
  • Select your SQL file and click on the “Go” option.
  • Now, wait until your database is imported.
Import MySQL Database step by step
Import MySQL Database step by step

Importing the MySQL database by Command-line interface

Beginners do not want to learn command because they think, remembering command is very hard work but that is not true. If you always work with commands then you don’t need to remember those commands. All commands you are using in your daily programming life will be automatically set in your mind.

Professionals want to work with command because writing less command does more work.

If you have a bigger size database then you will face so many issues to import that database by the user interface. You can try the command-line interface to import a bigger size database.

To import a database by CLI, you have to follow these steps:

Import MySQL database by Command line
Import MySQL database by Command line
  • First, copy your SQL file and keep in any drive without any folder because it will be easy to write the location of the file in command prompt.
  • Now open XAMPP folder and inside it open MySQL folder and again inside it open bin folder. “C:\xampp\mysql\bin
  • Next, open command prompt from this folder or set path in the command prompt of the current folder. To open a command prompt from this folder, write CMD in the address bar of the current folder. (It is in windows operating system).
  • Now write this command to import database. “mysql -u root -p database_import_test < D:\ajax_test.sql“. Here root is the database username, you can put your database username. Generally, the root is the default username of the localhost. database_import_test is my database name and after symbol our database file with their respective path.
  • Next, press the enter button and it will ask for your database password. If you have set the password of the database then enter your password and then press enter otherwise directly press enter.
  • Now it will take time to import the database.

Finally, I hope this tutorial will be very helpful for all of you. Share this tutorial with your friends to help others.

Read another tutorials:

Leave a Reply

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

error: Content is protected !!