MySQL

MySQL 사용자 비밀번호 변경

RYU™ 2011. 4. 27. 10:16
반응형

MySQL 사용자 비밀번호 변경


MySQL 사용자 비밀번호 변경
mysql>update user set password=password('비밀번호') where user='아이디';
mysql>flush privileges;



mysql PATH
echo PATH=$PATH:/usr/local/mysql/bin >> /etc/profile && source /etc/profile


mysql-opt
#!/bin/sh
./configure --prefix=/usr/local/mysql --with-charset=euc_kr --without-debug
make
make install
~
~
~
~
~
~


mysql 계정생성
$1: 디비명, $2: 디비아이디, $3: 디비비밀번호
### 디비계정 발급 ###
create database $1;
insert into db values('localhost','$1','$2','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');"
insert into user values('localhost','$2',password('$3'),'N','N','N','N','N','N','N','N','N','N','N','N','N','N');"


mysql 계정생성 및 삭제(스크립트)
########################## 계정생성 ##########################

[root@server mysql]# vi create_db.sh
#!/bin/bash
# $1 : db_name
# $2 : db_id
# $3 : db_password

if [ "$3" != "" ]; then

touch /tmp/mysql_dbusersetup_temp
echo "create database $1;" >> /tmp/mysql_dbusersetup_temp
echo "insert into db values('localhost','$1','$2','y','y','y','y','y','y','y','y','y','y');" >> /tmp/mysql_dbusersetup_temp
echo "insert into user values('localhost','$2',password('$3'),'n','n','n','n','n','n','n','n','n','n','n','n','n','n');" >> /tmp/mysql_dbusersetup_temp

echo "MYSQL 관리자 패스워드"
/usr/local/mysql/bin/mysql -u root -p mysql < /tmp/mysql_dbusersetup_temp

rm -f /tmp/mysql_dbusersetup_temp

echo "MYSQL 관리자 패스워드 입력2"
/usr/local/mysql/bin/mysqladmin -u root -p reload

else
echo "USAGE: $0 DB명 DB아이디 DB비밀번호"
echo ""
fi

exit 0
~
~
~
~
~
~
~
~
[root@server mysql]#





########################## 계정삭제 ##########################

[root@server mysql]# vi delete_db.sh
#! /bin/bash

# $1 : db_name
# $2 : db_id

if [ "$2" != "" ]; then

touch /tmp/mysql_dbuserdel_temp

echo "drop database $1;" >> /tmp/mysql_dbuserdel_temp
echo "delete from db where user = '$2';" >> /tmp/mysql_dbuserdel_temp
echo "delete from user where user = '$2';" >> /tmp/mysql_dbuserdel_temp

echo "MYSQL 관리자 패스워드 입력"
/usr/local/mysql/bin/mysql -u root -p mysql < /tmp/mysql_dbuserdel_temp

rm -f /tmp/mysql_dbuserdel_temp

echo "MYSQL 관리자 패스워드 입력2"
/usr/local/mysql/bin/mysqladmin -u root -p reload

else
echo "USAGE: $0 db명 db아이디"
echo ""
fi

exit 0
~
~
~
~
~
~
~
[root@server mysql]#

반응형