I try to write a script, which create database and tables in it.

For example, my bash file create attempt:


mysql -u root -p
use dbname;

Is executed joining into mysql console and that all. Script not create any table in database and not executed exit from mysql console.

How to correct create the script for that task?

1 Answer 1


Couple of different ways to do this. The easiest may be

mysql -u root -p <<EOF
use dbname;
create ....

This feeds everything between the command line and the EOF into mysql as input.

  • Easiest, and exactly that what I need. Thanks! Sep 25, 2018 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.