Take the 2-minute tour ×

I have a sql schema dump from phpmyadmin. I want to create a new database from that schema on a new machine. I have tried this:

mysql -uuser -ppwd < schema.sql

It says no database is selected. I know that I could CREATE database first then import, but is there an easier way to do this? I plan to do it in a script.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

You can even embed CREATE DATABASE statement in your SQL.

share|improve this answer
mysql -uuser -ppwd name_of_data_base < schema.sql
share|improve this answer
I got this error: ERROR 1049 (42000): Unknown database 'name_of_data_base' –  Wei Shi Dec 27 '11 at 2:10
You do have to put the name of the DB you want to use in that place. Since you didn't say what your db's name is, I put in "name_of_db" as a placeholder. –  Marc B Dec 27 '11 at 2:15
but the problem is I want to create a new DB and import schema at the same time. There is no DB in MySQL when I import. –  Wei Shi Dec 27 '11 at 2:45

Your Answer


