This article will show you How to export a copy of MySQL database in Xampp Server by using command line interface or Command Prompt (CMD) and How to import an MYSQL database backup file to your database server by using command line interface or Command Prompt (CMD). This is very useful for personal backups of our sites and for importing backups from other servers.
There are Two methods to import and export MYSQL database.
1) By Using PhpMyAdmin
2) Command Prompt (CMD)
To Export MYSQL Database
Method 1 – PhpMyAdmin
1. Log in to Phpmyadmin.
2. Select Your database from the list of the database on the left shown in Figure Below
3. Click on the “Export” from the Right top set of tabs.
4. Click the “Go” button, and, at the prompt, save the file to your local computer.
5. it will save in .sql Format or you can choose the format what you want from the dropdown.
To Import MYSQL Database
Method 1 – PhpMyAdmin
1. Check once the database you need has already been created. If it is not created please first create the database.
CAUTION:
If we import a backup file to the database that already has content, it will replace the existing content so be careful While Importing a database.
2. open phpMyAdmin, select your database from the list that is on the left.
3. Click the “Import” from the right side top set of tabs.
4. Then Click on the “Choose” button that is next to theĀ “Location of the Database file.”
5. Browse to your local SQL file and click “Open.” If it is a zipped file or .sql both will be accepted.
6. Click the “Go” button at the bottom. Wait while your database imports. Depending on the size, this can take a few minutes.
7. You should get a message like this:
Import has been successfully finished, X queries executed.
If you instead receive an error, please try the Second Method Command Prompt (CMD)
To Export MYSQL Database
Method 2 – Command Prompt (CMD)
1. Run cmd command
2. Go to the mysql bin folder in xampp installation directory
( By default I installed xampp server in local disk C )
3.In CMD Type cd C:\xampp\mysql\bin
Export command
mysqldump -u username -p databasename > filename.sql
OR
mysqldump -u username -p databasename > D:\Sample\filename.sql
To Import MYSQL Database
Method 2 – Command Prompt (CMD)
1. Run cmd command
2. Go to MySQL bin folder in xampp installation directory
( By default I installed xampp server in local disk c )
3. In CMD Type cd C:\xampp\mysql\bin
Import command
mysql -u username -p databasename < D:\Sample\filename.sql
OR
mysql -u username -p databasename < filename.sql
Note: The above command will export database file to the current directory where you are in (i.e) C:\xampp\mysql\bin in this location