• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Managing MySQL Using Systemd As A Non Root User

by admin

To facilitate a non root user, e.g. the mysql OS user, to stop and start MySQL Server using OS level system administration tools which rely on Systemd. The following entry in the sudoers file will allow the OS user mysql to stop and start the mysql server via the OS administration wrapper.

# visudo
## MySQL Admin
Cmnd_Alias MYSQLADMIN = /usr/bin/systemctl stop mysqld, /usr/bin/systemctl start mysqld,/usr/bin/systemctl restart mysqld
mysql ALL=MYSQLADMIN

As the mysql OS user , the Service can now be stopped / started as expected.

$ sudo systemctl stop mysqld
$ systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2016-06-06 12:34:28 AEST; 1s ago
Process: 11633 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 11617 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11637 (code=exited, status=0/SUCCESS)
$ sudo systemctl start mysqld
$ systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-06-06 12:34:38 AEST; 1s ago
Process: 11697 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 11682 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11701 (mysqld)
CGroup: /system.slice/mysqld.service
└─11701 /usr/sbin/mysqld --daemonize

Note: MySQL 5.6 does not natively use the systemd wrappers, even on supported OSes. It will still use the SysV scripts, typically in /etc/init.d. These can be stopped/started without any special privileges. Special attention is required, however, if the DB is scheduled to start on system boot, as in this scenario, root file permissions may exist on, eg lock file/error log.

Filed Under: CentOS/RHEL 7, Linux, mysql

Some more articles you might also be interested in …

  1. How To Configure Restricted Bash Shell in Linux
  2. “uname” Command Examples to Check UNIX/Linux Version
  3. arch-chroot: command not found
  4. nice: command not found
  5. CentOS / RHEL 6 : How to disable telnet service
  6. depmod: command not found
  7. grub-script-check: command not found
  8. jobs Command Examples in Linux
  9. Linux OS Service ‘rpcidmapd’
  10. “shutdown” Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright