首页 > 代码库 > shell脚本:实现MySQL创建数据库和删除数据库的脚本

shell脚本:实现MySQL创建数据库和删除数据库的脚本

OS操作系统:CentOS release 6.8 (Final)


[root@sky9896chapter11]# vi createdatabase.sh     #批量创建数据库

#!/bin/sh

PATH="/var/lib/mysql/bin:$PATH"

MYUSER=root

MYPASS=*******

      MYCMD="mysql  -u$MYUSER  -p$MYPASS "

for dbname in  test skyboy skygirl xiaoting bingbing

do

    $MYCMD  -e "create database$dbname"

Done


[root@sky9896chapter11]# vi dropdatabase.sh     #批量删除数据库

#!/bin/sh

PATH="/var/lib/mysql/bin:$PATH"

MYUSER=root

MYPASS=****

MYCMD="mysql -u$MYUSER  -p$MYPASS "

for dbname intest  skyboy skygirl xiaoting bingbing

do

    $MYCMD  -e "drop database $dbname"

Done

 

[root@sky9896chapter11]# sh droopdatabase.sh

ERROR 1008(HY000) at line 1: Can‘t drop database ‘test‘; database doesn‘t exist

ERROR 1008(HY000) at line 1: Can‘t drop database ‘skyboy‘; database doesn‘t exist

ERROR 1008(HY000) at line 1: Can‘t drop database ‘skygirl‘; database doesn‘t exist

ERROR 1008(HY000) at line 1: Can‘t drop database ‘xiaoting‘; database doesn‘t exist

ERROR 1008(HY000) at line 1: Can‘t drop database ‘bingbing‘; database doesn‘t exist

 

[root@sky9896chapter11]# sh createdatabase.sh

ERROR 1007(HY000) at line 1: Can‘t create database ‘test‘; database exists

ERROR 1007(HY000) at line 1: Can‘t create database ‘skyboy‘; database exists

ERROR 1007(HY000) at line 1: Can‘t create database ‘skygirl‘; database exists

ERROR 1007(HY000) at line 1: Can‘t create database ‘xiaoting‘; database exists

ERROR 1007(HY000) at line 1: Can‘t create database ‘bingbing‘; database exists



本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1955264

shell脚本:实现MySQL创建数据库和删除数据库的脚本