MySQL的启动方法有很多种,下面对比、总结这几种方法的一些差异和特性,下面实验的版本为MySQL 5.6。如有疏漏或不足,敬请指点一二。

 

1:使用mysqld启动、关闭MySQL服务

mysqld是MySQL的守护进程,我们可以用mysqld来启动、关闭MySQL服务,关于mysqld, MySQL 5.6官方介绍资料如下所示:

mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.

When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.

The mysqld program has many options that can be specified at startup. For a complete list of options, run this command:

shell> mysqld --verbose --help

MySQL Server also has a set of system variables that affect its operation as it runs. System variables can be set at server startup, and many of them can be changed at runtime to effect dynamic server reconfiguration. MySQL Server also has a set of status variables that provide information about its operation. You can monitor these status variables to access runtime performance characteristics.

如果MySQL是rpm方式安装的话,mysqld位于/usr/sbin下,如果MySQL是二进制安装的话,mysqld则位于bin目录下面。

[root@localhost ~]# whereis mysqld

mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz

[root@localhost ~]# /usr/sbin/mysqld stop

2016-06-27 14:52:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-06-27 14:52:54 9315 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

 

2016-06-27 14:52:54 9315 [ERROR] Aborting

 

2016-06-27 14:52:54 9315 [Note] Binlog end

2016-06-27 14:52:54 9315 [Note] /usr/sbin/mysqld: Shutdown complete

 

[root@localhost ~]# /usr/sbin/mysqld start

2016-06-27 14:52:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-06-27 14:52:59 9316 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

 

2016-06-27 14:52:59 9316 [ERROR] Aborting

 

2016-06-27 14:52:59 9316 [Note] Binlog end

2016-06-27 14:52:59 9316 [Note] /usr/sbin/mysqld: Shutdown complete

 

 

2:使用mysqld_safe启动、关闭MySQL服务

很多时候,人们会纠结mysqld与mysqld_safe的区别. 其实mysqld_safe是一个脚本,一个非常安全的启动、关闭MySQL服务的脚本。它实际上也是调用mysqld来启动、关闭MySQL服务。关于mysqld_safe,可以参考官方文档mysqld_safe MySQL Server Startup Script

 

3:使用mysql.server启动、关闭MySQL服务

[root@localhost mysql]# ./mysql.server  stop

Shutting down MySQL..[  OK  ]

[root@localhost mysql]# ./mysql.server  start

Starting MySQL..[  OK  ]

[root@localhost mysql]# 

mysql.server其实也是一个脚本,它通过调用msqld_safe来启动、关闭MySQL服务。部分脚本脚本如下

[root@localhost mysql]# more mysql.server 

#!/bin/sh

# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB

# This file is public domain and comes with NO WARRANTY of any kind

 

# MySQL daemon start/stop script.

 

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based

# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.

# When this is done the mysql server will be started when the machine is

# started and shut down when the systems goes down.

 

# Comments to support chkconfig on RedHat Linux

# chkconfig: 2345 64 36

# description: A very fast and reliable SQL database engine.

 

# Comments to support LSB init script conventions

### BEGIN INIT INFO

# Provides: mysql

# Required-Start: $local_fs $network $remote_fs

# Should-Start: ypbind nscd ldap ntpd xntpd

# Required-Stop: $local_fs $network $remote_fs

 

4:使用mysqld_multi启动、关闭MySQL服务

当服务器上运行了多个MySQL实例时,mysqld_multi是一个非常棒的管理MySQL服务器的工具。当然在使用前,你必须提前做配置

[root@localhost mysql]# /usr/bin/mysqld_multi stop 1

 

[root@localhost mysql]# /usr/bin/mysqld_multi start 1

mysqld_multi is designed to manage several mysqld processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status.

mysqld_multi searches for groups named [mysqldN] in my.cnf (or in the file named by the --defaults-file option). N can be any positive integer. This number is referred to in the following discussion as the option group number, or GNR. Group numbers distinguish option groups from one another and are used as arguments tomysqld_multi to specify which servers you want to start, stop, or obtain a status report for. Options listed in these groups are the same that you would use in the[mysqld] group used for starting mysqld. (See, for example, Section 2.10.5, “Starting and Stopping MySQL Automatically”.) However, when using multiple servers, it is necessary that each one use its own value for options such as the Unix socket file and TCP/IP port number. For more information on which options must be unique per server in a multiple-server environment, see Section 5.6, “Running Multiple MySQL Instances on One Machine”.

5:使用service 启动、关闭MySQL服务

service mysql start

 

service mysql stop

 

service mysql restart

其实如果你对service比较熟悉的话,就会知道运行上面命令,其实是service命令去找/etc/init.d下的相关的mysql脚本去执行启动、关闭动作。

[root@DB-Server init.d]# ls my*

mysql  mysql.server

[root@DB-Server init.d]# 

 

 

6: 使用/etc/init.d/mysql启动、关闭MySQL服务。

如果你非常了解方法5,那么就多了这么一个启动数据库的方式。其实/etc/init.d/mysql也是一个脚本,它调用mysqld_safe脚本来启动MySQL服务。如下所示,你会看到相关代码

[root@DB-Server bin]# /etc/init.d/mysql start

Starting MySQL....[  OK  ]

[root@DB-Server bin]# /etc/init.d/mysql stop

Shutting down MySQL..[  OK  ]

[root@DB-Server bin]# 

 

6:使用mysqladmin关闭数据库

mysqladmin是一个执行管理操作的客户程序,这个命令可以使用安全模式关闭数据库,但是不能启动数据库。当然它可以停止和启动MySQL replication on a slave server

[root@DB-Server bin]# /usr/bin/mysqladmin -u root -p shutdown

Enter password:

参考资料:

http://blog.csdn.net/shuishoujushi/article/details/10827471

https://dev.mysql.com/doc/refman/5.6/en/mysqld-safe.html

Linux 平台MySQL启动关闭方式总结的更多相关文章

  1. 笔记整理--Linux平台MYSQL的C语言

    Linux平台MYSQL的C语言API全列表 - 第三只眼的专栏 - 博客频道 - CSDN.NET - Google Chrome (2013/8/18 22:28:58)   Linux平台MYS ...

  2. mysql启动关闭的批处理,感觉很好用在其他论坛帖子上找到的,感谢分享

    最近用mysql的时间比较多,每次都在计算机管理工具下面去启动,感觉很麻烦,于是搜索了下果然有前辈已经做出了这些东西,今天收藏整理,mysql启动关闭的批处理感觉很好用在其他论坛帖子上找到的,感谢互联 ...

  3. linux下mysql 启动命令

    1,使用service 启动.关闭MySQL服务 service mysql start service mysql stop service mysql restart 运行上面命令,其实是serv ...

  4. MySQL启动关闭添加到 /etc/init.d/mysqld

      cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld       然后就可以使用此命令启动/关闭 mysql: /etc/ini ...

  5. Linux下mysql启动失败

    原因:强制重启服务器之后,发现mysql启动 失败 解决方法:强制清空 报错路径下的tmp文件,清空之后在tmp下面新建一个文件夹,文件夹的名字在你清空tmp之后启动mysql系统会给你提示 欧克,完 ...

  6. Linux下Mysql启动异常排查方案

    遇到Mysql启动异常问题,可以从以下几个方面依次进行问题排查: (1)如果遇到“Can't connect to local MySQL server through socket '/tmp/my ...

  7. mysql启动关闭

    RedHat Linux (Fedora Core/Cent OS) 1.启动:/etc/init.d/mysqld start2.停止:/etc/init.d/mysqld stop3.重启:/et ...

  8. linux之mysql启动问题

    网站总是挂掉,查看到原来是mysql总是莫名其妙的挂掉 1.查看mysql日志的位置 mysql> show VARIABLES like '%log%'; +----------------- ...

  9. LNMP(Linux+Nginx+MySQL+PHP) yum方式安装Redis

    一.环境信息 CentOS Linux release 8.1.1911 (Core) Redis server v=5.0.3 二.yum方式安装 1.添加EPEL仓库 sudo yum insta ...

随机推荐

  1. DDD 领域驱动设计-在动手之前,先把你的脑袋清理干净

    惨不忍睹的翻译 英文原文:http://www.codeproject.com/Articles/339725/Domain-Driven-Design-Clear-Your-Concepts-Bef ...

  2. JavaWeb学习总结(五十二)——使用JavaMail创建邮件和发送邮件

    一.RFC882文档简单说明 RFC882文档规定了如何编写一封简单的邮件(纯文本邮件),一封简单的邮件包含邮件头和邮件体两个部分,邮件头和邮件体之间使用空行分隔. 邮件头包含的内容有: from字段 ...

  3. IO多路复用之epoll总结

    1.基本知识 epoll是在2.6内核中提出的,是之前的select和poll的增强版本.相对于select和poll来说,epoll更加灵活,没有描述符限制.epoll使用一个文件描述符管理多个描述 ...

  4. OpenCV2简单的特征匹配

    特征的匹配大致可以分为3个步骤: 特征的提取 计算特征向量 特征匹配 对于3个步骤,在OpenCV2中都进行了封装.所有的特征提取方法都实现FeatureDetector接口,DescriptorEx ...

  5. springmvc4环境简单搭建和定时任务

    之前复制粘贴创建了几个ssm的项目,然而回头让自己写的时候还是一头雾水,究其原因是spring的陌生.仅仅是写过几个helloworld而已.而且是照着写.我都不知道springmvc到底需要多少ja ...

  6. 基于OpenSLL的RSA加密应用(非算法)

    基于OpenSLL的RSA加密应用(非算法) iOS开发中的小伙伴应该是经常用der和p12进行加密解密,而且在通常加密不止一种加密算法,还可以加点儿盐吧~本文章主要阐述的是在iOS中基于openSL ...

  7. membership与成员资格

    membership成员资格是ASP.NET 成员资格为您提供了一种验证和存储用户凭据的内置方法.因此,ASP.NET 成员资格可帮助您管理网站中的用户身份验证.它包含以下功能 创建新用户和密码. 将 ...

  8. 基于CkEditor实现.net在线开发之路(4)快速布局,工具箱,模板载入,tab选项卡简单说明与使用

    上一章给常用的from表单控件属性页面,进行了简单说明和介绍,但是由于是在网页中做界面设计,操作肯定没有桌面应用程序方便,便捷,为了更方便的布局与设计,今天我主要说一下快速布局,工具箱,tab选项卡, ...

  9. 疯狂Android讲义 - 学习笔记(五)

    第五章 Android使用统一的Intent对象来封装“启动意图”,不管是启动Activity.Service组件.或者BroadcastReceiver等,提供了一致的编程模型.Intent设计有点 ...

  10. win7设置wifi热点

    netsh wlan set hostednetwork mode=allow ssid=名字 key=大于等于8位密码 net wlan start hostednetwork ---------- ...