利用Shell开发MySQL的启动脚本
2024-09-01 02:34:05
- MySQL实例部署情况
01:MySQL程序安装目录:/data/apps/mysql
02:MySQL实例3306的配置文件为:/data/mysql/3306/my.cnf
03:MySQL实例3306的PID文件为:/data/mysql/3306/mysql.pid
04:MySQL实例3306的socket文件为:/data/mysql/3306/mysql.sock
- 脚本内容如下
#!/bin/bash # # Load OS variables source /etc/bashrc source /etc/prefile # Define variables RETVAL= Port= User=root Pass=chenliang Pid=/data/mysql//mysql.pid Sock=/data/mysql//mysql.sock My=/data/mysql//my.cnf Path=/data/apps/mysql/bin # Determine the user to execute if [ $UID -ne $RETVAL ];then echo "Must be root to run scripts" exit fi # Load the local functions [ -f /etc/init.d/functions ] && source /etc/init.d/functions # Define functions start(){ if [ ! -f "$Pid" ];then $Path/mysqld_safe --defaults->& & RETVAL=$? ];then action "Start MySQL [3306]" /bin/true else action "Start MySQL [3306]" /bin/false fi else echo "MySQL 3306 is running" exit fi return $RETVAL } stop(){ if [ -f "$Pid" ];then $Path/mysqladmin -u$User -p$Pass -S $Sock shutdown >/dev/>& RETVAL=$? ];then action "Stop MySQL[3306]" /bin/true else action "Stop MySQL[3306]" /bin/false fi else echo "MySQL [3306] is not running" exit fi return $RETVAL } status(){ if [ -f "$Pid" ];then echo "MySQL [3306] is running" else echo "MySQL [3306] is not running" fi return $RETVAL } # Case call functions case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; restart) stop start RETVAL=$? ;; status) status RETVAL=$? ;; *) echo "USAGE:$0{start|stop|restart|status}" exit esac # Scripts return values exit $RETVAL
最新文章
- WebApi防重复提交方案
- 为Visual Studio更换皮肤和背景图
- BZOJ3823 : 定情信物
- shell 循环使用
- [msf]那些年儿跑过的字典
- AC题目简解-dp
- Cocos2d-x 学习资料收集
- <;php>;统计整个文件夹的大小
- Yii2.0官方高级模板的目录结构分析
- Java探秘之基本数据类型和包装类(int,Integer)(一)
- mapreduce新旧api对比
- Oracle数据库体系结构之进程结构(4)
- mongoDB-Cannot change the size of a document in a capped collection:
- AQS解析(未完成)
- Spring MVC 使用介绍(一)—— 概述
- ubuntu上安装docker
- Gym - 101480 CERC 15:部分题目题解(队内第N次训练)
- 【JEECG技术文档】表单配置-树形表单
- CentOS 设置 oracle 开机自动启动
- php连接mysql...mysqli和mysql