脚本须知:

  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 初始化脚本的更多相关文章

  1. MySQL初始化脚本mysql_install_db使用简介及选项参数

    mysql_install_db是一个默认放在.../mysql/scripts的一个初始化脚本. 该脚本可以在任何装有perl的操作系统上被使用,在5.6.8之前的版本,该脚本是一个shell脚本, ...

  2. jeecg安装——mysql数据库创建+手动执行初始化脚本

    国产的开源项目官方文档写得那么详细,已经是很厚道了,可惜俺这种菜鸟还是会碰到各种"小"问题,做个笔记先! 1.新建数据库: CREATE DATABASE jeecg DEFAUL ...

  3. docker mysql初始化多个sql脚本

    一.概述 现有一台服务器,需要部署mysql.其中mysql容器,需要在第一次启动时,执行多个sql文件. 文件名 说明 执行顺序 init.sql 创建数据库以及用户 1 users.sql 用户表 ...

  4. 分析MariaDB初始化脚本mysql_install_db

    在初始化MySQL的过程中经常会碰到各种问题,如 FATAL ERROR: Could not find ./bin/my_print_defaults ERROR: Can't create/wri ...

  5. MySQL初始化以及客户端工具的使用

    MySQL初始化以及客户端工具的使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是关系型数据库 关系型数据库通常是把所有的数据都组织成二维关系.之所以称为关系型数据库是 ...

  6. 【数据库】5.0 MySQL入门学习(五)——MySQL源码了解及MySQL初始化设置

    1.0 MySQL源码目录主要包括:客户端代码.服务端代码.测试工具.其他库文件.当然,看懂源代码得有一定的C语言基础. BUILD:各种平台的编译脚本,可以用来制作各平台的二进制版本 client: ...

  7. Linux初始化脚本

    以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...

  8. ubuntu系统安装初始化脚本

    ubuntu系统安装初始化脚本 经常安装卸载ubuntu,每次系统安装完成后要安装好多软件,一个个命令输很麻烦浪费时间,一个sh文件全搞定! 1. flashplayer下载:点击这里 2. Auda ...

  9. centos7 系统初始化脚本

    现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...

随机推荐

  1. CUB reduce errorinvalid configuration argument

    解决CUB reduce errorinvalid configuration argument问题 在写TensorFlow代码时遇到报错 CUB reduce errorinvalid confi ...

  2. LeetCode(120) Triangle

    题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacen ...

  3. Counting Cliques HDU - 5952 单向边dfs

    题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...

  4. centos配置jdk

    ########## config jdk ########## export JAVA_HOME=/usr/local/java/jdk1.7.0_79 export CLASSPATH=.:${J ...

  5. PAT Basic 1081

    1081 检查密码 本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能.该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母.数字和小数点 .,还必须既有字母也有数字. 输 ...

  6. ubuntu12.04 ppa安装git

    PPA地址:https://launchpad.net/~git-core/+archive/ppa 支持所有的Ubuntu版本. 运行命令: sudo apt-add-repository ppa: ...

  7. selenium2常用API介绍

    我们模拟web操作都是基于元素来操作的,我们首先要先确定元素,然后这个元素下对应的方法就可以看WebElement的方法. 1.点击操作 WebElement button=driver.findEl ...

  8. BZOJ 5390: [Lydsy1806月赛]糖果商店

    F[i][j]表示总重量为i,最上面那个盒子中糖果种类为j的方案数 每次新加一个盒子,或者在原来盒子中加入一个糖 F[i][0]为中间状态,优化转移(表示最上面那个盒子不能加糖果) #include& ...

  9. django_orm操作

    查询操作和性能优化 1.基本操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23   增   models.Tb1.object ...

  10. MongoDB学习-->Spring Data Mongodb-->MongodbTemplate

    配置文件application-dev.yml: server: port: 8888 mongo: host: localhost port: 27017 timeout: 60000 db: ma ...