MySQL 如何让mysql自动启动?(仅限 linux-cli)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9859381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:43:02  来源:igfitidea点击:

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

mysqlubuntuautostart

提问by vasilakisfil

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.

每次系统启动时如何让mysql启动?我需要在我有博客的专用服务器(ubuntu 发行版)中使用它,但是每次服务器出现故障时,启动 mysql 时都会停止。顺便说一句,我只能使用命令行。

采纳答案by Christian Giupponi

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

您可以通过使用来完成sysv-rc-conf,在基于 debian 的基础上,您可以安装它,sudo apt-get install sysv-rc-conf然后您可以选择在启动时使用守护程序名称上的简单 X 启动的内容,全部通过命令行

enter image description here

在此处输入图片说明

回答by inquiryqueue

update-rc.dallows 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:

update-rc.d允许在 Ubuntu 和 Debian Linux 系统上设置 init 脚本链接,以控制进入各种运行级别时 init 运行的服务。它应该能够将 mysql 添加到启动时运行的服务列表中:

sudo update-rc.d mysql defaults

If you later want to disable running mysql on bootup:

如果您以后想在启动时禁用运行 mysql:

sudo update-rc.d mysql remove

回答by Seanog

Run the following command to see your mysql current status:

运行以下命令以查看您的 mysql 当前状态:

/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:

要在每次系统启动时启动 mysql,请键入以下内容:

 sudo /sbin/chkconfig mysqld on

Result now from '--list' is:

现在'--list'的结果是:

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

回答by sausix

No answer helped. Finally chkconfigand update-rc.ddid not work with MySQL on my machine.

没有答案有帮助。最后chkconfigupdate-rc.d没有在我的机器上使用 MySQL。

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

解决方案,我有一个文件/etc/init/mysql.override其中包含

manual

i just deleted that file

我刚刚删除了那个文件

$ sudo rm /etc/init/mysql.override

回答by Flow Li

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

删除 /etc/init/mysql.override 在我的情况下完成了这项工作(HostEurope VPS with Ubuntu 12.04)

回答by Firemyst

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

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).

检查您的 /etc/init/mysql.conf 以确保您没有开始注释掉(就像我所做的那样)。

# 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

回答by Matt Healy

回答by Eric Thiele

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)

/etc/init.d/.depend.start(和它关机时的伙伴,.depend.stop)

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

这里有更多信息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.

我有 2 台服务器 - 启动后,1 台将运行 mysql,另一台则没有那么多。

On the box where mysql was starting at boot time:

在启动时启动 mysql 的框中:

  • 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
    
  • 甚至没有安装 chkconfig
  • 从 /etc/rc?.d/* 中的任何脚本返回到 /etc/init.d/mysql 的链接为零
  • 但是... /etc/init.d/.depend.start 包含:

    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.

当我简单地将此文件复制到问题服务器并重新启动时,mysql 已启动并正在运行。

回答by PJ Brunet

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.

使用 Debian 9,我今天安装了 MySQL 并输入了“rebo​​ot”,然后 mysqld 自动重新启动。也从我的 VPS 仪表板重新启动,mysqld 自动重新启动。简而言之,如果您有 Debian 9,则无需额外操作,它就可以工作。

回答by BabaNew

sudo chkconfig --level 345 mariadb on

did the trick for me.

帮我解决了这个问题。

(I'm running on ec2 Amazon Linux AMI release 2018.03)

(我在 ec2 Amazon Linux AMI 版本 2018.03 上运行)