Couldn't make a database in mysql using bash script ??

Avi lists at avi.co
Fri Jul 1 16:40:47 UTC 2011


Amrit Pal Pathak wrote:

> I used following code to make a database in mysql through bash
> script.but it couldn't make.it opens the mysql server in terminal
> just.
> 
> mysql -u root -p
> echo  "Enter password"
> read a
> create database test
> echo "press ctrl+d "
> echo "bye"

Because the

mysql -u root -p

is the command to get a shell in the mysql client, it's not a
programming interface to mysql. The usual way to do this would be to do 

echo "create database test" | mysql -u root -pPassword

having previously prompted for the username and password if preferable.
This wont pass you a shell, but it will execute 'create database test'
in one and print whatever output you'd normally get to terminal.

-- 
Avi




More information about the ubuntu-users mailing list