There's no reason for you to write this script. /etc/init.d/mysql
is an init(1)
script, so just use that:
# update-rc.d mysql defaults
If that doesn't work, you might need to look into the more advanced update-rc.d
options. For instance, maybe you are using an uncommon runlevel, and the default runlevels for the provided mysql
script don't include that.
If you were actually trying to get something to run on startup which doesn't already provide an init script, you'd need to remove the sudo
bit. init scripts run as root already. You actually have to drop permissions if you need your program to run as another user.