zoukankan      html  css  js  c++  java
  • 非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 stuff in here if you don't
    # want to do the full Sys V style init stuff.
    
    touch /var/lock/subsys/local
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    
    # 以非root用户启动随开机启动mysql服务
    su - mysql -c /data/mysql/scripts/is_start_status_mysql.sh
    [root@db130 ~]# 

    3、reboot测试验证。

  • 相关阅读:
    小X的密码破译
    小X的加法难题
    足球联赛
    机器分配
    化装晚会
    Soundex编码
    迷之阶梯
    使用JMeter做压力测试
    SCOI 2010 序列操作
    动态求区间K大值(权值线段树)
  • 原文地址:https://www.cnblogs.com/bjx2020/p/10861003.html
Copyright © 2011-2022 走看看