Alex Rivera | Logout

How to create a database from shell command in MySQL?

Asked 2010-03-11T20:24:12.350
206

I'm looking for something like createdb in PostgreSQL or any other solution that would allow me to create database with a help of a shell command. Any hints?

Edit
Report

2 Answers

266

You mean while the mysql environment?

create database testdb;

Or directly from command line:

mysql -u root -e "create database testdb"; 
answered 2010-03-11T20:27:50.313
188
cat filename.sql | mysql -u username -p # type mysql password when asked for it

Where filename.sql holds all the sql to create your database. Or...

echo "create database `database-name`" | mysql -u username -p

If you really only want to create a database.

answered 2010-03-11T20:29:26.697

Your Answer