Home > Database > Mysql Tutorial > ubuntu linux下mysql开机自启动_MySQL

ubuntu linux下mysql开机自启动_MySQL

WBOY
Release: 2016-06-01 13:26:47
Original
2395 people have browsed it

Ubuntu

bitsCN.com

Mysql自带了一个非常好用的管理mysql服务的脚本,默认在$MYSQL_HOME/support-files路径下,文件名是mysql.server。$MYSQL_HOME是mysql的安装根目录,下同。mysql.server的用法:Usage: ./mysql.server

1. 预使mysql开机自启动,首先需要注册mysql为ubuntu下的服务。

直接拷贝mysql.server文件至/etc/init.d/目录下即可。

sudo cp $MYSQL_HOME/support-files/mysql.server /etc/init.d/mysql.server

sudo chmod +x /etc/init.d/mysql.server

2. 修改my.cnf,指定mysql的启动用户

定义:命令1=”./mysql.server start –user=user1“,命令2=”./mysql.server start”。(注意,命令1、2的区别在于红色部分)

在编译安装mysql的过程中,若执行configure命令时指定“–user=user1”参数,则mysql将由用户user1启动,在mysql.server文件中会有“user=user1”这样一行来指定mysql的启动用户,但该行指定的启动用户并未生效。即,需要使用命令1来启动mysql,命令2启动失败。

为了使命令2生效,同时为了mysql开机自启动,需要修改my.cnf,在[mysqld]区块下添加“user=user1”这样一行。如此,便可使用命令2启动mysql,mysql也可以成功开机自启动。

3. 设置mysql开机自启动

让mysql开机自己启动

1.$ sudo update-rc.d -f mysql.server defaults

root@leroy-linux:/etc/init.d# update-rc.d -f mysql.server defaults

Adding system startup for /etc/init.d/mysql ...

/etc/rc0.d/K20mysql.server -> ../init.d/mysql.server

/etc/rc1.d/K20mysql.server -> ../init.d/mysql.server

/etc/rc6.d/K20mysql.server -> ../init.d/mysql.server

/etc/rc2.d/S20mysql.server -> ../init.d/mysql.server

/etc/rc3.d/S20mysql.server -> ../init.d/mysql.server

/etc/rc4.d/S20mysql.server -> ../init.d/mysql.server

/etc/rc5.d/S20mysql.server -> ../init.d/mysql.server

如果不想让mysql开机自己启动,可以使用

1.$ sudo update-rc.d -f mysql.server remove

root@sean-linux:/etc/init.d# update-rc.d -f mysql remove

Removing any system startup links for /etc/init.d/mysql ...

/etc/rc0.d/K21mysql.server

/etc/rc1.d/K21mysql.server

/etc/rc2.d/S19mysql.server

/etc/rc3.d/S19mysql.server

/etc/rc4.d/S19mysql.server

/etc/rc5.d/S19mysql.server

/etc/rc6.d/K21mysql.server

4. 服务的使用

启动mysql:service mysql.server start;

停止mysql:service mysql.server stop;

查看mysql运行状态:service mysql.server status。

另外,要确保mysql启动用户user1对$MYSQL_HOME具有读写权限,否则会因权限问题导致mysql启动失败。

补充

Ubuntu 取消 Apache及MySQL等自启动

1. 装个 sysv-conf-rc

2. sudo update-rc.d -f mysql remove 删除mysql随机器启动的服务

sudo update-rc.d -f apache2 remove 删除apache2随机器启动的服务

3. 查看/etc/rc2.d/里面的apache和mysql启动脚本,通常都是两个阿拉伯数字后再接一个英文字母,再加脚本名称。英文字母是S的都是会自动启动的,K则相反。所以只要找到apache和mysql的启动脚本,把S改成K就可以了。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template