Importing / Loading a Mysql backup / database from a .sql file – In Shell

Mar 23rd, 2009 | By | Category: Technology

I was appalled when the first page of search results for this came up with instructions on how to do this for a Windows server.  So I felt it my duty to add to the tutorials out there for people actually running a real web server (BSD/Linux/Etc)

Parse in the .sql file into an already existing DB

In shell simply issue the following command

$ mysql -u root -p db-name < backup-file.sql

To create a new DB and then import

Login to Mysql:
$ mysql -u root -p

Now create database called sales using SQL statement:

mysql> CREATE DATABASE myDB;
mysql> quit;

Now restore database, enter:
$ mysql -u root -p myDB < /path/to/your-DB-file.sql
Easy Peasy isn’t it?

Tags: , , , , , , , ,

Leave a Comment