17

How would I configure my CentOS Linux server to automatically start mysql when the server is started following a shutdown?

I'm aware of the init.d path...

/etc/rc.d/init.d

...and I can see mysqld in this folder. I believe that placing items (i.e. by symbolic link) in this folder means that they should start on server restart.

But this did not happen for me.

Background

Our central IT desk restarted our virtualised CentOS servers over the weekend. The server was available following restart but the MySQL database had not restarted also.

Thoughts?

therobyouknow
  • 471
  • 4
  • 8
  • 18
  • some answers relevant https://stackoverflow.com/questions/9859381/how-make-mysql-start-automatically-linux-cli-only – n611x007 Sep 01 '15 at 08:58

2 Answers2

32

Use chkconfig:

chkconfig --level 345 mysqld on
Yongfeng
  • 103
  • 3
alvosu
  • 8,357
  • 24
  • 22
  • +1 Thanks BUT should this be chkconfig --level 345 mysqld on NOT chkconfig --levels 345 mysqld on ? http://linuxcommand.org/man_pages/chkconfig8.html I tried both. I'm guessing it worked by there was no message or anything, after typing it, I just got another prompt. Any way to tell if it makes mysql restart automatically? – therobyouknow Feb 07 '11 at 09:06
  • 3
    @Rob: run `chkconfig --list mysqld` to show what runlevels that init script is set for. – Scott Pack Feb 07 '11 at 13:42
  • Couldn't get `chkconfig` installed.... `Package 'chkconfig' has no installation candidate` – inorganik Mar 02 '16 at 17:16
2

To enable mysql service on startup, use following command.

systemctl enable mysqld.service

It will create appropriate symbolic link for you.

Kumar
  • 823
  • 3
  • 20
  • 43