Monday, 6 August 2012

Mysql Console Commands - Export and Import database from command line


Mysql Console Commands - Export and Import database from command line


1) Create a new Database.
create database mydb


2) List of all databases.
show databases


3)Create Backup of all Database.
mysqldump -h localhost -u username -p password –all-databases > dumpAllDatabase.sql


4) Create Backup of database (database name mydb) OR Export database into file.
mysqldump -h localhost -u username -p mydb > dump.sql


4) Create Backup of database structure only.
mysqldump -u username -p -no-data mydb > dump.sql

5) Import SQL file into  database
mysql -h localhost -u username -p password mydb < dump.sql


Note: When you add -p in command line, It will prompt for database password. In this case just type/paste the correct password.