0

I am unsure of the syntax I would need to use to do:

/etc/init.d/mysql restart or /etc/init.d/mysqld restart

This is for scripts so it can be easily ported onto Ubuntu (mysql) or CentOS (mysqld).

I'm just wanted a quick one liner (if possible). Or would I need to actually do a "find" for what is in /etc/init.d/

Zippyduda
  • 107
  • 2
  • 7
  • 19

2 Answers2

0

This should work on most linux distributions:

sudo service mysqld restart
mvp
  • 111,019
  • 13
  • 122
  • 148
0

Different systems seems to name the mysql service differently, either mysql or mysqld. So you could try and restart the ones that exist.

[ -f /etc/init.d/mysql ] && /sbin/service mysql restart
[ -f /etc/init.d/mysqld ] && /sbin/service mysqld restart

This will likely break when distros convert the mysql service to systemd, as the startup files are no longer in /etc/init.d/

nos
  • 223,662
  • 58
  • 417
  • 506
  • Yeah this kind of works. For Ubuntu 12 just removed /sbin/ Would have thought there would be "do this, if not exists, do this" kind of command in one :) – Zippyduda Nov 30 '12 at 11:56
  • Well, you could always put the 2 lines here on one line with a `||` between them, or just a `;` – nos Nov 30 '12 at 12:02