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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. “Metadata File Does Not Match Checksum” Issue When Yum Installs or Updates Package
  2. How to Change Time Interval to Fall Back to Secondary DNS Server in CentOS/RHEL
  3. How to Install MySQL Cluster on a single server for testing purposes
  4. Linux Interview Questions : Open Files / Open File Descriptors
  5. Order of environment calls for different OS shells in Linux
  6. LVM ISCSI Physical Volume Not Available After Server Reboot
  7. Anonymous User Fails to Upload File to VSFTP Server
  8. How to transfer files securely using sftp (examples included)
  9. How to configure NTP server and client in CentOS / RHEL 7
  10. CentOS / RHEL : How to configure vsftpd to use ports other than the default ports 20 and 21

You May Also Like

Primary Sidebar

Recent Posts

  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • How Realms Work in Oracle Database Vault
  • How to use Privilege Analysis in Oracle Database
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary