rm: cannot remove '/var/lock/subsys/mysql': Permission denied

接手一台MySQL  5.6.40-log MySQL Community Server数据库服务器 ,关闭MySQL服务时遇到下面错误,MySQL的错误日志中没有出现这个信息,另外,重启MySQL服务时没有问题。只是在关闭MySQL服务时遇到这个错误信息,看着挺别扭的。当然这个是在非root用户下启动/关闭,如果在root用户下启动/关闭则没有这个错误信息:

 

$ service mysqld stop
Shutting down MySQL.... SUCCESS!
rm: cannot remove '/var/lock/subsys/mysql': Permission denied
 
$ service mysqld start
Starting MySQL. SUCCESS!

 

找到MySQL服务的配置文件 /etc/rc.d/init.d/mysqld,分析定位到stop部分代码,如下所示:

 

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
 
..................................
 
  'stop')
    # Stop daemon. We use a signal here to avoid having to know the
    # root password.
 
    if test -s "$mysqld_pid_file_path"
    then
      mysqld_pid=`cat "$mysqld_pid_file_path"`
 
      if (kill -0 $mysqld_pid 2>/dev/null)
      then
        echo $echo_n "Shutting down MySQL"
        kill $mysqld_pid
        # mysqld should remove the pid file when it exits, so wait for it.
        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
      else
        log_failure_msg "MySQL server process #$mysqld_pid is not running!"
        rm "$mysqld_pid_file_path"
      fi
 
      # Delete lock for RedHat / SuSE
      if test -f "$lock_file_path"
      then
        rm -f "$lock_file_path"
      fi
      exit $return_value
    else
      log_failure_msg "MySQL server PID file could not be found!"
    fi
    ;;

检查验证发现当前用户(非root用户),没有删除/var/lock/subsys/mysql文件的权限。

 

$ ls -lrt /var/lock
lrwxrwxrwx. 1 root root 11 Jun  5  2020 /var/lock -> ../run/lock
$ ls -lrt /var/lock/subsys/
total 0
-rw-r--r-- 1 root  root  0 Oct 15  2020 network
-rw-r--r-- 1 root  root  0 Oct 15  2020 local
-rw-r--r-- 1 root  root  0 Oct 15  2020 mysql
 
$ rm /var/lock/subsys/mysql
rm: cannot remove ‘/var/lock/subsys/mysql’: Permission denied

 

 

解决办法,修改/etc/rc.d/init.d/mysqld中lockdir变量的值,指定到用户mysql有权限的目录。问题解决。另外一种解决方式是通过授予用户访问文件的权限。但是感觉没有第一种方式好。因为一些原因,现在DBA使用JumpServer登录系统时,只允许非root账号访问。

 

lockdir='/data/mysqldata'
上一篇:Windows版mysql安装教程


下一篇:最新MySQL安装指南(补充视频)