shell脚本:实现MySQL创建数据库和删除数据库的脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本:实现MySQL创建数据库和删除数据库的脚本相关的知识,希望对你有一定的参考价值。
OS操作系统:CentOS release 6.8 (Final)
[[email protected]]# 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
[[email protected]]# 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
[ro[email protected]]# 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
[[email protected]]# 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创建数据库和删除数据库的脚本的主要内容,如果未能解决你的问题,请参考以下文章