1. Import

I assume you have SQL file(database) which you want to import using cmd. For example, we have stud.sql database file

First, let’s just create a database from http://localhost/phpmyadmin/ And suppose we created a database named students

If you are using WampServer go to wamp64\bin\mysql\mysql5.7.11\bin(for me it is this directory) place your SQL file(stud.sql) here in this folder

If you are using XAMPP go to xampp\mysql\bin place your SQL(stud.sql) file here in this folder

Open cmd and go to above path where we put our SQL file. Like for me, it is

C:\xampp\mysql\bin

And Run below command. Here username will be your username(It is root for me)

1. Run command

mysql -u root -p

hit Enter and it will ask for the password. If you have one enter it and if you don’t just hit Enter again.

2. Then Run command to select database

use students

hit Enter

3. After that Run this command to specify file we want to import

source stud.sql

hit Enter

And your import process it started.

Well, there is also a short way of doing this. Just go to the  C:\xampp\mysql\bin>  and run below command

mysql -u root -p students < stud.sql

and read this here that says It is better to use the full path of the SQL file.

so I tried it and it works if your SQL file is at desktop no problem. Run command like below

mysql -u root -p students < C:\Users\Vicky\Desktop\stud.sql

 

2. Export

To export database,  I just have this. You can run below command in cmd from the same directory C:\xampp\mysql\bin>

mysqldump -u root -p students > studentsbkp.sql

And your exported SQL file will be at C:\xampp\mysql\bin\studentsbkp.sql

Be kind to one another. Take care!

Tags:
, , ,
No Comments

Post A Comment