linux下mysql启动的方法有几种(windows和mac下启动比较方便):

mysqld — The MySQL Server
mysqld_safe — MySQL Server Startup Script
mysql.server — MySQL Server Startup Script
mysqld_multi — Manage Multiple MySQL Servers

当然还有通过service来起mysql server的。默认安装后会注册为service的,所以再重启机器后也mysql server也启动了的。这就能解释为什么机器重启后mysql client还能连接。

service mysqld start
service mysqld stop
service mysqld restart

这4种命令又有什么区别呢?什么情况下使用哪个命令?

  • mysqld就是mysql server的启动命令入口。mysqld管理所有对mysql data directory的访问。mysql data directory包含数据库, 表, 日志,状态文件等。当mysql server启动后,它监听所有的client网络链接,并代表它们访问data directory。mysql server有一系列system variables。这些系统变量可以在启动时设置,有些也可能在启动后运行时设置。它们都会改变server运行时的行为。它还有一系列的status variables。这些status变量可以查看mysql server运行时的性能状态。通过运行mysqld -verbose --help来查看所有的参数。
  • mysqld_safe: 这是unix系统中推荐的启动mysql server的方法。它添加了一些安全特性,比如说当server出现error时重启,以及log一些logging info到err日志中。mysqld_safe运行mysqld并重写了它的一些默认行为。mysqld_safe的option与mysqld的option大部分差不多。对不认识的option会传给mysqld。mysqld_safe可以读取所有[mysqld][server][mysqld_safe][safe_mysqld]下的option。mysqld_safe会查找并读取--log-error这个参数,这样以后log信息都会写到这里面。
  • mysql.server 这个脚本使用mysqld_safe来启动mysql server.在它启动前,它会更改location到mysql的安装目录,然后运行mysqld_safe。
    shell> mysql.server start
    shell> mysql.server stop
    Before mysql.server starts the server, it changes location to the MySQL installation directory, and then invokes mysqld_safe. To run the server as some specific user, add an appropriate user option to the [mysqld] group of the /etc/my.cnf option file, as shown later in this section. (It is possible that you must edit mysql.server if you've installed a binary distribution of MySQL in a nonstandard location. Modify it to change location into the proper directory before it runs mysqld_safe. If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future, so you should make a copy of your edited version that you can reinstall.)
    
    mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown.
    
    To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your /etc/rc* files.
  • mysqld_multi 这个就不细谈了,以后用到再说。顾名思义就是管理多个mysql server使用的。
mysqld_safe Options

Format	Description
--basedir	Path to MySQL installation directory
--core-file-size	Size of core file that mysqld should be able to create
--datadir	Path to data directory
--defaults-extra-file	Read named option file in addition to usual option files
--defaults-file	Read only named option file
--help	Display help message and exit
--ledir	Path to directory where server is located
--log-error	Write error log to named file
--malloc-lib	Alternative malloc library to use for mysqld
--mysqld	Name of server program to start (in ledir directory)
--mysqld-version	Suffix for server program name
--nice	Use nice program to set server scheduling priority
--no-defaults	Read no option files
--open-files-limit	Number of files that mysqld should be able to open
--pid-file	Path name of server process ID file
--plugin-dir	Directory where plugins are installed
--port	Port number on which to listen for TCP/IP connections
--skip-kill-mysqld	Do not try to kill stray mysqld processes
--skip-syslog	Do not write error messages to syslog; use error log file
--socket	Socket file on which to listen for Unix socket connections
--syslog	Write error messages to syslog
--syslog-tag	Tag suffix for messages written to syslog
--timezone	Set TZ time zone environment variable to named value
--user	Run mysqld as user having name user_name or numeric user ID user_id

参考文档:

  • https://dev.mysql.com/doc/refman/5.6/en/programs-server.html

发表评论