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

前端之家收集整理的这篇文章主要介绍了shell脚本:实现MySQL创建数据库和删除数据库的脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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


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

#!/bin/sh

PATH="/var/lib/@R_403_198@/bin:$PATH"

MYUSER=root

MYPASS=*******

MYCMD="@R_403_198@ -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/@R_403_198@/bin:$PATH"

MYUSER=root

MYPASS=****

MYCMD="@R_403_198@ -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

原文链接:https://www.f2er.com/bash/391503.html

猜你在找的Bash相关文章