日期:2014-05-16  浏览次数:20692 次

Linux 下 MySQL 启动与关闭 说明
一.启动

1.1  MySQL 进程

可以用ps 命令查看进程:

[root@rac2 ~]# ps -ef|grep mysql

root     2161     1  0 09:38 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe--datadir=/var/lib/mysql --pid-file=/var/lib/mysql/rac2.pid

mysql    2418  2161  0 09:38 ?        00:00:00 /usr/sbin/mysqld--basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin--user=mysql --log-error=/var/lib/mysql/rac2.err--pid-file=/var/lib/mysql/rac2.pid --socket=/var/lib/mysql/mysql.sock--port=3306

root     3628  3596  0 09:57 pts/1    00:00:00 grep mysql



1.1.1 mysqld — The MySQL Server

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

When MySQLserver starts, it listens for network connections from client programs andmanages access to databases on behalf of those clients.

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

shell> mysqld--verbose --help

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

-- mysqld 进程是MySQL Server 最核心的进程。mysqld 进程crash 或者出现异常,MySQLServer 基本上也就无法正常提供服务了。



1.1.2 mysqld_safe — MySQL Server Startup Script

mysqld_safe is the recommended way to start a mysqld server on Unix. mysqld_safe adds somesafety features such as restarting the server when an error occurs and loggingruntime information to an error log file. A description of error logging isgiven later in this section.

mysqld_safe triesto start an executable named mysqld. To override the default behavior andspecify explicitly the name of the server you want to run, specify a --mysqld or--mysqld-version option to mysqld_safe. You can also use --ledir to indicate thedirectory where mysqld_safe should look for the server.

mysqld_safe readsall options from the [mysqld], [server], and [mysqld_safe] sections in optionfiles. For example, if you specify a [mysqld] section like this, mysqld_safe willfind and use the --log-error option:

[mysqld]

log-error=error.log

For backwardcompatibility, mysqld_safe also reads [safe_mysqld] sections, although youshould rename such sections to [mysqld_safe] in MySQL 5.5 installations.

--mysqld_safe 会帮助我们来监控mysqld 进程的状态,当mysqld 进程crash 之后,mysqld_safe会马上帮助我们重启mysqld 进程。但前提是我们必须通过mysqld_safe 来启动MySQLServer,这也是MySQL AB 强烈推荐的做法。



1.1.3 mysql.server — MySQL Server Startup Script

MySQLdistributions on Unix include a script named mysql.server. It can be used onsystems such as Linux and Solaris that use System V-style run directories tostart and stop system services. It is also used by the Mac OS X Startup Itemfor MySQL.

mysql.server canbe found in the support-files directory under your MySQL installation directoryor in a MySQL source distribution.

--mysql.server 脚本放在support-files 目录下。 即:/usr/share/mysql

If you use theLinux server RPM package (MySQL-server-VERSION.rpm), the mysql.server scriptwill be installed in the /etc/init.d directory with the name my