Give Non Root user access to start thesqld service

rootservicesudo

I have a Non Root User abc and want to give the user sudo rights only to restart, start or stopmysqld service. i.e sudo service mysqld restart. How can I do it so?

I would like to do the same to usergroup too!!

Best Answer

You need to add the following lines in /etc/sudoers

dba01 ALL=/sbin/service mysqld start
dba01 ALL=/sbin/service mysqld stop
dba01 ALL=/sbin/service mysqld restart

this config will allow dba01 user to execute all three commands.

Now here is the output

[dba01@APP01 root]$ sudo /sbin/service mysqld restart
[sudo] password for dba01:
Shutting down mysqld:                                        [  OK  ]
Starting mysqld:                                             [  OK  ]

If you try to run any other service

[dba01@APP01 root]$ sudo /sbin/service ip6tables restart
Sorry, user dba01 is not allowed to execute '/sbin/service ip6tables restart' as root on APP01.