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
FormatDescription
--basedirPath to MySQL installation directory
--core-file-sizeSize of core file that mysqld should be able to create
--datadirPath to data directory
--defaults-extra-fileRead named option file in addition to usual option files
--defaults-fileRead only named option file
--helpDisplay help message and exit
--ledirPath to directory where server is located
--log-errorWrite error log to named file
--malloc-libAlternative malloc library to use for mysqld
--mysqldName of server program to start (in ledir directory)
--mysqld-versionSuffix for server program name
--niceUse nice program to set server scheduling priority
--no-defaultsRead no option files
--open-files-limitNumber of files that mysqld should be able to open
--pid-filePath name of server process ID file
--plugin-dirDirectory where plugins are installed
--portPort number on which to listen for TCP/IP connections
--skip-kill-mysqldDo not try to kill stray mysqld processes
--skip-syslogDo not write error messages to syslog; use error log file
--socketSocket file on which to listen for Unix socket connections
--syslogWrite error messages to syslog
--syslog-tagTag suffix for messages written to syslog
--timezoneSet TZ time zone environment variable to named value
--userRun 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