When working with MySQL I often use tools like PhpMyAdmin or sequelPro, which is a nice GUI way to manipulate MySQL database. But it won’t work sometime while importing/exporting larger databases. So sometimes you need to do mysql import on the command line.
Export a Large Database
$ mysqldump -u [USERNAME] -p [DBNAME] | gzip > [/path_to_file/DBNAME].sql.gz
MySQL Import a Large Database
# First, unzip the file.
$ gzip -d [/path_to_file/DBNAME].sql.gz
Login to mysql
$ [/path_to_mysql/]mysql -u [USERNAME] -p
Wipe out the old database and replace it with the new dump
SHOW DATABASES;
DROP DATABASE [DBNAME];
CREATE DATABASE [DBNAME];
USE [DBNAME];
SOURCE [/path_to_file/DBNAME].sql;
Final Words
Well, that was it! I hope this will help you. of course, you can always have a quick look at this tutorial again if you forget something. Intention of my blog is to provide quick helps to the developers. I generally does not go much into the theories. I believe, the more you practice the more you learn.