Svenson's  Bulletin Board Forum Index Svenson's Bulletin Board
Bulletin Board for boat building and model airplane building enthusiasts.
 
AlbumAlbum   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script to create mysql db and setup admin user.

 
Post new topic   Reply to topic    Svenson's Bulletin Board Forum Index -> MySQL
View previous topic :: View next topic  
Author Message
craig
Site Admin


Joined: 19 Feb 2006
Posts: 40

PostPosted: Tue Feb 28, 2006 7:18 am    Post subject: Script to create mysql db and setup admin user. Reply with quote

# mysql $DB -uroot -e"grant all on $DB.* to $USR@$FHN identified by '$PSW'"

DB="database_name"

FHN=localhost.localdomain
USR="userid"

PSW="password"
echo "db=$DB,USR=$USR,PSW=$PSW"

ROOTP=rootsmysqlpassword
MYSQL="mysql -u root -p$ROOTP --force mysql"
MYSQLADMIN="mysqladmin -u root -p$ROOTP --force"

echo "Step 0"

$MYSQLADMIN drop $DB

$MYSQL <<EOF
delete from host where db = "$DB";
delete from user where user = "$USR";
delete from db where db = "$DB";
EOF

echo "Step 1"









$MYSQL <<EOF_HT

insert into
host(host,db,Select_priv,Insert_priv,Update_priv,
Delete_priv,Create_priv,Drop_priv,Alter_priv)
values('$FHN','$DB','Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');

EOF_HT
echo "Step 2"




$MYSQL <<EOF_UT

insert into user (host,user,password)
values('$FHN','$USR',password('$PSW'));

EOF_UT

echo "Step 3"



$MYSQL <<EOF_DB

insert into db (host,db,user,Select_priv,Insert_priv,Update_priv,
Delete_priv, Create_priv,Drop_priv,Alter_priv)
values ('$FHN','$DB','$USR','Y','Y','Y','Y','Y','Y','Y');

EOF_DB

echo "Step 4"






$MYSQLADMIN create $DB








$MYSQLADMIN reload




mysql -h$FHN -u$USR -p$PSW $DB <<TEST_EOF

create table tbl1 (
name char(30) not null,
phon char(30) not null,
addr char(30),
primary key(phon,name)
);

show tables;

drop table tbl1;

TEST_EOF
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Svenson's Bulletin Board Forum Index -> MySQL All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group