Search code examples
mysqldatabaseshellcommand-linecommand

How to create a database from shell command in MySQL?


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?


Solution

  • 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.