Create database in Shell Script - convert from PHP

Posted by snaken on Stack Overflow See other posts from Stack Overflow or by snaken
Published on 2010-05-05T10:25:54Z Indexed on 2010/05/05 10:28 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I have the following PHP code that i use to create a databaase and grant permissions to a user:

$con = mysql_connect("IP.ADDRESS","user","pass");
mysql_query("CREATE DATABASE ".$dbuser."",$con)or die(mysql_error());
mysql_query("grant all on ".$dbuser.".* to  ".$dbname." identified by '".$dbpass."'",$con) or die(mysql_error());

I want to perform these same actions but from within a shell script. Is it just something like this:

MyUSER="user"
MyPASS="pass"
MYSQL -u $MyUSER -h -p$MyPASS -Bse "CREATE DATABASE $dbuser;'
MYSQL -u $MyUSER -h -p$MyPASS -Bse "GRANT ALL ON ${DBUSER}.* to  $DBNAME identified by $DBPASS;"

© Stack Overflow or respective owner

Related posts about php

Related posts about shell