views:

44

answers:

3

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

+1  A: 

You can use SQL on the command line:

echo 'CREATE DATABASE dbname;' | mysql <...>

Or you can use mysqladmin:

mysqladmin create dbname
Lukáš Lalinský
+2  A: 

You mean while the mysql environment?

create database testdb;

Or directly from command line:

mysql -u root -e "create database testdb"; 
Felix Kling
mysql -u root -e "create database testdb"; Thats what i was looking for :) thank you
koszikot
A: 

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 databasename" | mysql -u -u username -p

if you really only want to create a database.

Kris