Currently, my MySQL server starts on every server boot. For a couple reasons, this is undesirable behavior. Is there a way to disable this behavior?
9 Answers
Since 15.04 you can simply do:
sudo systemctl disable mysql
- 193,181
- 53
- 473
- 722
- 2,221
- 1
- 14
- 11
-
6Indeed. For 15.04, this is the answer you seek. – CommandZ Dec 03 '15 at 19:03
-
Awesome, finally I found a solution for this! The other methods don't work to me. – rneves Mar 22 '16 at 13:08
-
1I can't start it again, how do I start mysql after the command? – rneves Mar 22 '16 at 13:21
-
@rneves did you try `enable` or `reenable`? – thebugfinder Apr 12 '16 at 23:48
-
1@thebugfinder I've tried `enable`, I don't know about `reenable`, but `enable` forces me restart the computer to start mysql again – rneves Apr 13 '16 at 14:56
-
@rneves then after `enable` you should run `sudo systemctl start mysql` – thebugfinder Apr 13 '16 at 19:57
-
Didn't work for me .. I had `insserv: warning: current start runlevel(s) (empty) of script 'mysql' overrides LSB defaults (2 3 4 5).` – alexandre-rousseau Oct 10 '17 at 06:04
-
2BTW, `sudo systemctl is-enabled mysql` help to check whether enabled currently. – Eric Aug 17 '18 at 08:02
-
If you're using MariaDB, use `sudo systemctl disable mariadb`. – Amil Waduwawara Jul 05 '19 at 08:57
-
3I confirm it works in Ubuntu **18.04** too – Manuel Jordan Nov 03 '19 at 16:13
To prevent mysql from starting on boot:
Open the terminal: Ctrl+Alt+T
Open the
mysql.conffile:nano /etc/init/mysql.confComment out the
start online near the top of the file, thestart onmight be spread across two lines, so comment out both. (comment adding#at the beginning)
If you want to manually start mysql, use the following command:
service mysql start
Taken liberally from here.
- 13,397
- 12
- 56
- 73
-
3This is a very usefull answer for more than one initiation at start up. – maniat1k Mar 22 '12 at 15:26
-
3Tried, I have ``/usr/sbin/mysqld`` and ``/bin/sh /usr/bin/mysqld_safe`` running. Commented out everything but didn't helped. – Emin Mastizada Sep 16 '15 at 20:33
-
-
in Linux Mint 18.2 Cinnamon I removed /etc/init/mysql.conf with no change. Mysql server still running on startup. @thebugfinder solution worked for me – flyingdrifter Nov 06 '17 at 14:24
-
In Ubuntu 18.04, sudo systemctl disable mysql will prevent mysql-server from autostarting on boot.
For linux, there are 3 main init systems: Systemd, Upstart and SysV. Although nearly all Linux systems run on Systemd. The other two init systems might also co-exist in your system.
For Systemd, use command sudo systemctl disable mysql;
For Upstart, use echo manual >> /etc/init/mysql.override;
For SysV, run the following command sudo update-rc.d mysql disable
If you'd like to find which init system is running on your server, please read this answer.
- 280
- 2
- 5
Things have changed quite a bit in Ubuntu now. I think from version 11 onwards. MySQL is handled by Upstart while Apache still uses traditional SysV init scripts
For MySQL, you can use the new override feature in Upstart to modify the starting behaviour:
sudo echo "manual" >> /etc/init/mysql.override
For more info, see the section "Disabling a Job from Automatically Starting" in the Upstart Cookbook.
As Apache still uses the traditional SysV init scripts you can use
sudo update-rc.d -f apache2 remove
to remove the links from /etc/rcX.d or, alternatively use
sudo update-rc.d apache2 disable
which "disables" the script by changing it from a start script to a stop script. This is reversible by
sudo update-rc.d apache2 enable
Most of this information I got from here: https://askubuntu.com/a/40077/24678
- 380
- 1
- 4
- 7
-
If you want to restore the service `sudo update-rc.d apache2 defaults` – bentech Jan 17 '18 at 10:20
There are two Guis I can think of. From Applications -> Ubuntu Software Center search for "boot up manager". After installing you will find it in the System -> Administration -> BootUP-Manager. Another is Webmin. Webmin uses your browser. After installing point your browser to https://localhost:10000/ Look for services and work it from there.
- 786
- 5
- 12
Well I am using Ubuntu 20.04 on my laptop. The problem I faced is that mysql service starts at boot up and takes 32 seconds to move to the next step in the sequence of bootup. So I decided to disable it from the boot sequence to make it boot faster. For this I followed the below steps:
I checked for mysql running status by command:
sudo service mysql status
The result showed the status as in the snippet shown below. There I noticed the source of it's loading - " loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) "
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-04-16 03:45:09 IST; 26min ago
So I decided to disabled it using systemctl command as:
sudo systemctl disable mysql
result of the above command:
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable mysql
Removed /etc/systemd/system/multi-user.target.wants/mysql.service.
Now I can manually start / stop or check the status of mysql service by using the following commands:
sudo service mysql start
sudo service mysql stop
sudo service mysql status
I hope this might help. Cheers.
- 71
- 1
- 2
Actually, there is also another method to accomplish this, via the sysv-rc-conf tool.
You can install it by typing
sudo apt-get install sysv-rc-conf
It allows you to take control over all available services, including running/stopping them in place and configuring services' operation per runlevel.
Edit: You have to run tis tool as root:
sudo sysv-rc-conf
- 1,029
- 1
- 9
- 18
Or if your really laze like me you could just open a Terminal session and then type:
sudo perl -pi.orig -e 's/start\s+on/#start\s+on/' /etc/init/mysql.conf && sudo perl -pi.orig -e 's/and\s+/#and/g' /etc/init/mysql.conf
You can then just issue a reboot command then your system will boot-up without mysql started.
- 70,934
- 124
- 466
- 653
- 4,036
- 2
- 19
- 19
-
1This command could be improved. It is adding a `+` leaving the line like this: `#start+on blahblahblah` but it works! – Lucio Dec 22 '13 at 00:41
You can use chkconfig tool package
$ chkconfig --level 345 mysqld off
- 209
- 3
- 7
- 109
-
2Please elaborate your answer. Why do you think this solves the question? You could e.g. add a link to a manual as reference. – Byte Commander Jul 28 '16 at 22:30