mysql 初始化脚本
脚本须知:
1. 确认mysql的数据目录,二进制日志目录,中继日志的目录,安装目录的位置
2. 初始化会对前三个目录执行清空操作,不过清空前该脚本对其进行了压缩打包统一存放在/tmp目录下
3. 脚本运行完应该查看服务是否启动正常,如果不正常请检查配置文件/etc/my.cnf和相关目录的权限属主问题
4. 此脚本对需要快速恢复mysql到初始状态的情况比较适宜 比如(主从复制出现问题,已经不能简单的靠2进制日志解决,此时可以用该脚本初始化mysql salve
服务器 然后用完全备份加2进制重新与主mysql完成同步)
#!/bin/bash
# # function
clean_dir(){
cd $
name=`echo $ | sed 's@/@@' | sed 's@/@_@g'`
tar -jcf $name.tar.bz2 * &> /dev/null
\mv -f $name.tar.bz2 /tmp/
rm -rf *
} mysql_init(){
$basedir/scripts/mysql_install_db --defaults-file=/etc/my.cnf \
--basedir=$basedir \
--datadir=$datadir \
--user=mysql
if [ $? -eq ];then
echo "----------->initiate is finished"
else
echo "------------>initiate is failed"
return
fi
} info_check(){
read -p "Please give the MySQL data directory: " datadir
if [ ! -d $datadir ];then
echo 'directory does not exist !'
exit
fi
read -p "Please give a binary file directory: " bindir
if [ ! -d $bindir ];then
echo 'directory does not exist !'
exit
fi
read -p "Please give the relay log directory: " relaydir
if [ ! -d $relaydir ];then
echo 'directory does not exist !'
exit
fi
read -p "Please give the Mysql Install directory: " basedir
if [ ! -d $basedir ];then
echo 'directory does not exist !'
exit
fi
echo -e "\033[31mPlease verify your give Mysql information:\n\
MySQL data directory: $datadir\n\
MySQL Install directory: $basedir\n\
Binary file directory: $bindir\n\
Relay log directory: $relaydir\n\[0m"
} # main
info_check
sleep
while true;do
read -p "Confirm please enter yes, change directory information please input C: " ans
if [ $ans == "yes" ];then
break
elif [ $ans == "c" -o $ans == "C" ];then
info_check
sleep
else
echo "Option only supports: yes | c"
continue
fi
done
echo -e "\033[31mMySQL database initialization......\033[0m"
service mysqld stop &> /dev/null || kill `cat /var/run/mysqld/mysqld.pid`
dir=`echo $datadir $bindir $relaydir | xargs -n echo | sort -u`
for i in $dir ;do
clean_dir $i
done
# If the MySQL service is started
# ps -ef | grep -E "mysqld[[:space:]]+" | awk -F ' ' '{ print $8 }' | xargs dirname | sed -r 's@[^/]+/?$@@'
mysql_init $datadir $basedir
if [ $? -eq ];then
chown -R mysql.mysql {$datadir,$bindir,$relaydir}
service mysqld start
fi
mysql 初始化脚本的更多相关文章
- MySQL初始化脚本mysql_install_db使用简介及选项参数
mysql_install_db是一个默认放在.../mysql/scripts的一个初始化脚本. 该脚本可以在任何装有perl的操作系统上被使用,在5.6.8之前的版本,该脚本是一个shell脚本, ...
- jeecg安装——mysql数据库创建+手动执行初始化脚本
国产的开源项目官方文档写得那么详细,已经是很厚道了,可惜俺这种菜鸟还是会碰到各种"小"问题,做个笔记先! 1.新建数据库: CREATE DATABASE jeecg DEFAUL ...
- docker mysql初始化多个sql脚本
一.概述 现有一台服务器,需要部署mysql.其中mysql容器,需要在第一次启动时,执行多个sql文件. 文件名 说明 执行顺序 init.sql 创建数据库以及用户 1 users.sql 用户表 ...
- 分析MariaDB初始化脚本mysql_install_db
在初始化MySQL的过程中经常会碰到各种问题,如 FATAL ERROR: Could not find ./bin/my_print_defaults ERROR: Can't create/wri ...
- MySQL初始化以及客户端工具的使用
MySQL初始化以及客户端工具的使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是关系型数据库 关系型数据库通常是把所有的数据都组织成二维关系.之所以称为关系型数据库是 ...
- 【数据库】5.0 MySQL入门学习(五)——MySQL源码了解及MySQL初始化设置
1.0 MySQL源码目录主要包括:客户端代码.服务端代码.测试工具.其他库文件.当然,看懂源代码得有一定的C语言基础. BUILD:各种平台的编译脚本,可以用来制作各平台的二进制版本 client: ...
- Linux初始化脚本
以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...
- ubuntu系统安装初始化脚本
ubuntu系统安装初始化脚本 经常安装卸载ubuntu,每次系统安装完成后要安装好多软件,一个个命令输很麻烦浪费时间,一个sh文件全搞定! 1. flashplayer下载:点击这里 2. Auda ...
- centos7 系统初始化脚本
现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...
随机推荐
- echarts事件中获取当前实例
直接使用this即可
- 更改BootStrap popover的默认样式
.popover { position: absolute; top: 0; left: 0; z-index: 1060; display: none; max-width: 276px; padd ...
- Git基本操作笔记:初始化,用户设置,撤销修改
1. Git 初始化 git init git remote add repos_name repos_url git add . git commit -m 'commit message' gi ...
- ise与win8兼容解决方案
win8中ise无法加载code,显示impact4.exe停止运行. 解决方法如下: 找到程序安装路径 1.进入文件夹 D:\Xilinx\14.6\ISE_DS\ISE\lib\nt64 把li ...
- 【laravel】Disabling CSRF for Specific Routes - Laravel 5
原文 http://www.camroncade.com/disable-csrf-for-specific-routes-laravel-5/ Disabling CSRF for Specific ...
- Head First Python (二)
if...else... 1 movies = ["The Holy Grail",1975,"Terry Jones & Terry Gilliam" ...
- LeetCode(189) Rotate Array
题目 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...
- zoj 4054
#define ll long long ; int t; ll ans,tmp; char s[N]; int main() { scanf("%d",&t); whil ...
- 实践自己的WebSite______流水
尝试从头至尾搭建一个MVC的网站,主要以流水的方式进行进度和记录,而不讨论技术的部分. 1,在Controller下创建两个文件夹,分别为sys和Business,分别对应于系统功能和业务逻辑.比如登 ...
- day05_02 IDE介绍及设置
notepad++比较麻烦,使用IDE工具进行程序开发 集成开发环境(IDE,Integrated Development Environment) VIM #经典的linux下的文本编辑器 Emac ...