I installed MariaDB server to my machine. While setting up, I was met with the problem of whether I should have it enabled all the time, as the documentation I follow suggests with these steps:
sudo yum install mariadb mariadb-server
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
systemctl start
andsystemctl enable
do different things.enable
will hook the specified unit into relevant places, so that it will automatically start on boot, or when relevant hardware is plugged in, or other situations depending on what's specified in the unit file.start
starts the unit right now.disable
andstop
are the opposite of these, respectively.This means that when you first install MariaDB, you might want to run
systemctl enable mariadb.service
to enable it so it starts on boot. You might also want to runsystemctl start mariadb.service
, or just reboot, in order to start MariaDB. To stop MariaDB, runsystemctl stop mariadb.service
(it will start again on next boot or when you manually start it). To disable it so it doesn't start on boot anymore, runsystemctl disable mariadb.service
.Update:
As noted in gerardw's answer, starting from version 220, released in may 2015, both
enable
anddisable
started to take the optional--now
switch in order to also start or stop the unit, depending on the used command.To both disable and stop a unit with the same command, use
systemctl disable mariadb.service --now
. Similarly, to both enable and start a unit, usesystemctl enable mariadb.service --now
.Source: systemctl man page
From the
systemctl
manpage:Essentially,
enable
marks the service for starting up on boot, andstart
actually starts the service immediately.As of systemctl version 220, enable and disable support a --now switch to start / stop services concurrent with the enabling / disabling.
e.g.
systemctl --now enable foobar.service
Use
systemctl --version
to check your installed version.