Start MySQL on Startup

I installed MySQL, and changed the configuration so the databases are stored on a separate hard drive. In the process MySQL has stopped starting up automatically. When I start the computer, I need to run the command:

sudo service mysql start

to get MySQL to run. How do you get MySQL to start on boot?


Solution 1:

Enter this command:

sudo update-rc.d mysql defaults

Solution 2:

Excuse me for being a bit off-topic by hijacking the slightly different issue here to provide solution to similar case. Since I stumbled over this thread by trying to solve my somewhat related issue I beg for your pardon.

I was having issues with starting mysql in an lxc container running Ubuntu 16.04. I tried update-rc.d mysql defaults as well as systemctl enable mysql.service several times but mysql didn't come up on boot. There wasn't even a log entry regarding some error to fix.

The lxc container is getting its network configuration via host's lxc configuration file but still was configured to start DHCP client enabled by default. By disabling DHCP in lxc container I stumbled over solution by accident. This was the reason for mysql not starting as it was waiting for DHCP client to finish. And DHCP didn't finish due to missing any response from unavailable DHCP service.

So, just in case you stumble over the same question here and find yourself in a similar dilemma try this: Edit /etc/network/interfaces and comment-out lines reading

auto eth0
iface eth0 inet dhcp

Solution 3:

Ubuntu with upstart init

Up to 14.04 Ubuntu uses upstart for init so we have to check its config: If /etc/init/mysql.override exists and contains manual then automatic starting of mysql is disabled.

Remove .override and reload config:

rm /etc/init/mysql.override
initctl reload-configuration

Alternatively if SysV init is used

First cleanup old startup config, then write new default config to avoid error System start/stop links for /etc/init.d/mysql already exist.

Execute as root:

update-rc.d -f mysql remove
update-rc.d mysql defaults