root启动mysql_非root用户随开机而启动mysql服务

非root用户随开机而启动mysql服务

今天验证了一下,非root用户随开机而启动msyql服务的脚本执行效果,特此简要记录如下:

环境:

192.168.142.130

mysql 5.6.41 源码安装

数据和安装目录都是mysql用户

需求:

需要在关机开机启动后,能自动启动mysql数据库服务

重点是:

开机自动运行脚本,可以将脚本的执行命令放在/etc/rc.d/rc.local 文件中,但是这样开机自动运行这个脚本的用户默认为root。

如果想以某个非root用户运行脚本,可以使用如下命令:su - user -c /home/user/run.sh注意格式:su(空格)-(空格)-c(空格)命令路径....

1、脚本内容

[mysql@db130 scripts]$ cat /data/mysql/scripts/is_start_status_mysql.sh

#!/bin/bash

#

# Author: Created by lww

# filename: /data/mysql/scripts/is_start_status_mysql.sh

# Date: 2019-05-14

# Description: This script is used to start mysql server.

# Version:1.1

#

#####################################################################################

is_start_status=`ps -ef|grep -Ew 'mysqld|mysqld_safe' | grep -vw 'grep' |  wc -l`

if [[ "$is_start_status" -ne 2 ]]; then

sleep 10

/data/mysql/percona_server/bin/mysqld_safe --defaults-file=/data/mysql/percona_server/conf/my.cnf &

fi

[mysql@db130 scripts]$

2、开启启动服务文件修改

[root@db130 ~]# cat /etc/rc.local

#!/bin/sh#

# This script will be executed*after*all the other init scripts.

# You can put your own initialization stuffin here if you don't

# want to dothe full Sys V style init stuff.touch /var/lock/subsys/localecho never > /sys/kernel/mm/transparent_hugepage/enabled

# 以非root用户启动随开机启动mysql服务su - mysql -c /data/mysql/scripts/is_start_status_mysql.sh[root@db130~]#

3、reboot测试验证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值