• 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. ncview: command not found
  2. CentOS / RHEL : How to change password hashing algorithm
  3. tuned-adm and Oracle
  4. Patch Management of Linux Servers Using Spacewalk
  5. How to Change the Default Character Set and Collation for a Database in MySQL
  6. CentOS / RHEL 7 : How to follow the mount order in /etc/fstab
  7. What is ioremap()
  8. Examples of mysqldump partial backups
  9. RHEL 7 – RHCSA Notes – input / output redirection
  10. CentOS / RHE 7 : How to Prevent Users from Using the Last 10 Passwords

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright