영국 yahoo에서 일하는 Matt Zandstra란 사람이 만든 쉘스크립트 입니다.

MySQL에 사용자와 그 사용자가 쓸 DB까지 생성해준다고 설명하네요.

사용법
$ mysql_create_user_and_db
usage: mysql_create_user_and_db [dbname] [yourpass] [rootpassword]

스크립트
----------------------------
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# author     Matt Zandstra 
# copyright  2006 getInstance (Matt Zandstra) 
# license    http://www.apache.org/licenses/LICENSE-2.0 
# version    CVS: $Id: mysql_create_user_and_db,v 1.1 2006/02/05 00:03:24 getinstance Exp $



progname=`basename $0`
mysqlcmd=mysql
mysqladmincmd=mysqladmin

usage () {
    echo "usage: $progname [dbname] [yourpass] [rootpassword]"
    exit 1;
}

die () {
    echo 1>&2 "$*"
    exit 1
}

if [ $# -lt 3 ]; then
	usage
fi

dbname=$1
dbuser=$dbname"_user"
dbpass=$2
rootpass=$3

#set -x
echo "INSERT INTO db VALUES ('localhost','$dbname','$dbuser','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');" | $mysqlcmd -u root -p$rootpass mysql || die

echo "INSERT INTO user VALUES ('localhost','$dbuser',password('$dbpass'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);" | $mysqlcmd -u root -p$rootpass mysql || die

$mysqladmincmd -u root -p$rootpass create $dbname || die
$mysqladmincmd -u root -p$rootpass reload || die
신고
크리에이티브 커먼즈 라이선스
Creative Commons License

Posted by ElegantCoder

Google Reader

, ,
Response
1974 Trackbacks 0 Comments

Leave a comment


티스토리 툴바