Mysql工作中使用过的脚本
创始人
2024-05-10 17:34:25
0


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

 

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...