OS 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
[Root[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
This article is from the "sky9890" blog, make sure to keep this source http://sky9896.blog.51cto.com/2330653/1955264
Shell script: Implementing MySQL to create a database and delete a database script