6.1 创建库
#! /bin/sh
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "**********【Is Createing the $dbname from the Ip $IP】***********"
/home/mysql/mysql/bin/mysqladmin -h $IP -u$user -p create $dbname
echo "*********【 Done Successful】*********"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
6.2 导入表结构
#! /bin/sh
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "***************【Is loading to $IP about $dbname 's table-DDL】"
/home/mysql/mysql/bin/mysql -h $IP -u$user -p $dbname <${dbname}-d.sql
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
6.3 导入表数据
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "***************【Is loading to $IP about $dbname 's table-SQL】"
/home/mysql/mysql/bin/mysql -h $IP -u$user -p $dbname <${dbname}-t.sql
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
6.4 删除指定库
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "please think it over before do it"
/home/mysql/mysql/bin/mysqladmin -h $IP -u$user -p drop $dbname
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
6.5 备份表结构
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "**************【Is starting to Copy the ddl】"
/home/mysql/mysql/bin/mysqldump -h $IP -u$user -p $dbname -d -R -E --triggers >${dbname}-d.sql
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
6.6 备份表数据
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "**************【Is starting to Copy the ddl】"
/home/mysql/mysql/bin/mysqldump -h $IP -u$user -p $dbname -t >${dbname}-t.sql
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
6.7 备份表数据和结构
echo "please input the dbName(eg:esfdbfe)"
read dbname
echo "please input the userName(eg:root)"
read user
echo "please input the hostIP(eg:10.114.30.33)"
read IP
echo "**************【Is starting to Copy the ddl】"
/home/mysql/mysql/bin/mysqldump -h $IP -u$user -p $dbname -R -E --triggers >${dbname}-d-t.sql
echo "************【Done Successful】**************"
1
2
3
4
5
6
7
8
9
10
11
12
13
6.8 创建用户
#! /bin/sh
echo "please input the userName(eg:root)"
read user
echo "please input the userPasswd"
read passwd
echo "please input the user you want to create(eg:esb)"
read newUser
echo "please input the user's passwd you want to create(eg:rootroot)"
read newUserPwd
echo "please input the dbtabase you want to grant to newUser(eg: esfdbfe)"
read dbtable
export log=createUser.log
/home/mysql/mysql/bin/mysql -u$user -p$passwd -e "CREATE USER '$newUser'@'%' IDENTIFIED BY '$newUserPwd';" >>$log
/home/mysql/mysql/bin/mysql -u$user -p$passwd -e "GRANT ALL ON $dbtable.* TO '$newUser'@'%';" >>$log
/home/mysql/mysql/bin/mysql -u$user -p$passwd -e "FLUSH PRIVILEGES;" >>$log