How make mysql start automatically ? (linux-cli only)
Asked Answered
S

9

49

How can i make mysql start every time the system boot ? I need that in a dedicated server(ubuntu distro) in which i have my blog, but every time the server goes down, on booting mysql is stopped. Btw i can use only command line.

Selfness answered 25/3, 2012 at 10:15 Comment(1)
related serverfault.com/questions/232046/…Margenemargent
M
36

You can do it by using sysv-rc-conf, on debian based you can install it with sudo apt-get install sysv-rc-conf then you can choose what start at boot with a simple X on the name of the deamon, all via command line

enter image description here

Maggio answered 25/3, 2012 at 10:19 Comment(5)
Again not working..I marked X mysql in all the runleves plus S but when rebooting service mysql status says mysql stop/waiting.Selfness
Sorry but what does the numbers mean on the top row?Contravene
From Ubuntu 12.10 on, sysv-rc-conf is the replacement for chkconfig recommended below. It also lets you use commands instead of the ncurses interface, in this case: sysv-rc-conf mysql on.Vacillate
And the equivalent for CentOS/RedHat is ntsysv (the title of the question suggested Linux systems)Immigration
It works like charm for me on various Ubuntu versions, but doesn't create the symlinks on Debian 7. Interestingly if I quit and restart the program it keeps the "X"-es I've marked, but the daemons don't run because the symlinks in /etc/rcX.d/ don't get created.Cammi
P
52

update-rc.d allows setting init script links on Ubuntu and Debian Linux systems to control what services are run by init when entering various runlevels. It should be able to add mysql to the list of services to run at boot:

sudo update-rc.d mysql defaults

If you later want to disable running mysql on bootup:

sudo update-rc.d mysql remove
Pyle answered 26/3, 2012 at 1:18 Comment(0)
M
36

You can do it by using sysv-rc-conf, on debian based you can install it with sudo apt-get install sysv-rc-conf then you can choose what start at boot with a simple X on the name of the deamon, all via command line

enter image description here

Maggio answered 25/3, 2012 at 10:19 Comment(5)
Again not working..I marked X mysql in all the runleves plus S but when rebooting service mysql status says mysql stop/waiting.Selfness
Sorry but what does the numbers mean on the top row?Contravene
From Ubuntu 12.10 on, sysv-rc-conf is the replacement for chkconfig recommended below. It also lets you use commands instead of the ncurses interface, in this case: sysv-rc-conf mysql on.Vacillate
And the equivalent for CentOS/RedHat is ntsysv (the title of the question suggested Linux systems)Immigration
It works like charm for me on various Ubuntu versions, but doesn't create the symlinks on Debian 7. Interestingly if I quit and restart the program it keeps the "X"-es I've marked, but the daemons don't run because the symlinks in /etc/rcX.d/ don't get created.Cammi
W
25

Run the following command to see your mysql current status:

/sbin/chkconfig mysqld --list

it will return a line such as below:

 mysqld             0:off   1:off   2:off   3:off   4:off   5:off   6:off

to make mysql start every time the system boots, type the following:

 sudo /sbin/chkconfig mysqld on

Result now from '--list' is:

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
Whitmore answered 5/2, 2013 at 12:13 Comment(4)
Great answer. Simple and effective.Tila
My CentOS server always started mysqld at bootup. But since yesterday it didn't any more. But this solution helped me. Great, thanks!Trent
Tried to apply this solution, but when system is rebooted and I check my mysql service status, it says: MySQL is not running, but PID file exists. I know this is an old thread but we're running out of options. By the way, /sbin/chkconfig mysql --list command output seems to be fair. We've tried all the answers in this page but sadly with no luck.Glossectomy
seems like it doesn't even try to run the script inside /etc/init.d/Glossectomy
C
7

No answer helped. Finally chkconfig and update-rc.d did not work with MySQL on my machine.

Solution, I had a file /etc/init/mysql.override which contained

manual

i just deleted that file

$ sudo rm /etc/init/mysql.override
Clap answered 31/12, 2013 at 15:21 Comment(0)
C
4

I had the same problem, so I checked how I disabled it in the first place:

https://askubuntu.com/questions/138487/how-to-keep-apache-and-mysql-from-starting-automatically

Check your /etc/init/mysql.conf to make sure you don't have start on commented out (like I did).

# MySQL Service

description     "MySQL Server"

author          "Mario Limonciello <[email protected]>"

start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]
...

Rebooted the machine and it works.

$ sudo service mysql status
mysql start/running, process 972
Commonplace answered 5/8, 2013 at 20:37 Comment(0)
S
4

Deleting /etc/init/mysql.override did the job in my case (HostEurope VPS with Ubuntu 12.04)

Stakeout answered 28/1, 2014 at 23:44 Comment(0)
M
1

Use the chkconfig command as per the manpage http://manpages.ubuntu.com/manpages/maverick/man8/chkconfig.8.html

Maurreen answered 25/3, 2012 at 10:17 Comment(0)
C
1

Another place to look for clues as to what is and isn't starting at boot time...

/etc/init.d/.depend.start (and its buddy at shutdown time, .depend.stop)

Here's a little more info http://www.pyenet.co.nz/2-202-1-customising-system-startup-and-boot-processes/

I had 2 servers - after booting, 1 would have mysql running, the other not so much.

On the box where mysql was starting at boot time:

  • chkconfig wasn't even installed
  • there were zero links from any scripts in /etc/rc?.d/* back to /etc/init.d/mysql
  • BUT... /etc/init.d/.depend.start contained:

    TARGETS = halt apache2 umountfs umountnfs.sh sendsigs networking umountroot reboot killprocs unattended-upgrades urandom mysql mdadm dns-clean landscape-client pppd-dns sysstat rsync sudo postfix single grub-common ondemand rc.local
    INTERACTIVE = apache2
    postfix: mysql
    single: killprocs dns-clean pppd-dns
    grub-common: apache2 unattended-upgrades postfix mysql mdadm dns-clean landscape-client pppd-dns sysstat rsync sudo
    ondemand: apache2 unattended-upgrades postfix mysql mdadm dns-clean landscape-client pppd-dns sysstat rsync sudo
    rc.local: apache2 unattended-upgrades postfix mysql mdadm dns-clean landscape-client pppd-dns sysstat rsync sudo
    

When I simply copied this file over to the problem server, and rebooted, mysql was up & running.

Callboy answered 14/1, 2015 at 17:22 Comment(0)
S
0

With Debian 9, I installed MySQL today and typed "reboot" and mysqld restarted automatically. Also rebooted from my VPS dashboard, mysqld restarted automatically. In short, if you have Debian 9, there's nothing extra to do, it just works.

Seljuk answered 21/9, 2017 at 23:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.