mysql关于mysql.server的总结

来源:这里教程网 时间:2026-03-01 11:46:18 作者:

1、mysql.server服务端工具,主要作用就是为了方便启动和关闭mysql服务,这个脚本中调用mysqld_safe来启动mysqld 2、RPM包安装时,发现/etc/rc.d/init.d/mysql和/usr/share/mysql/mysql.server里面的东西一模一样 3、mysql.server脚本其实也是调用mysqld_safe脚本去启动MySQL服务器的,但此时mysqld_safe不能使用参数选项即不能mysqld_safe --defaults-file这样的模式,此时只能使用默认的/etc/my.cnf配置文件    相当于mysql.server把参数传递给mysqld_safe,mysqld_safe再传递给mysqld 4、mysql.server传递给mysqld_safe的参数,可以显式看到的都是parse_server_arguments函数指定的参数,如下只能看到--datadir、--pid-file,但是也都是来自my.cnf    [root@mydb]# ps -ef|grep mysql    root      6687     1  0 19:38 pts/1    00:00:00 /bin/sh /mysql/mysql57/bin/mysqld_safe --datadir=/mysql/mysql57/data --pid-file=/mysql/mysql57/data/mydb.pid 5、my.cnf会覆盖mysql.server里的basedir和datadir配置    These may get overwritten by settings in the MySQL configuration files 解压文件安装时mysql.server存放于解压目录的support-files/mysql.server cp /mysql/mysql-5.5.25-linux2.6-i686/support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 700 /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 345 mysqld on service mysqld start RPM安装方式下,mysql.server存放于/usr/share/mysql/mysql.server [root@mydb mysql55rpm]# ll /etc/rc.d/init.d/mysql -rwxr-xr-x 1 root root 10585 Mar 10  2011 /etc/rc.d/init.d/mysql [root@mydb mysql55rpm]# ll /usr/share/mysql/mysql.server -rwxr-xr-x 1 root root 10585 Mar  9  2011 /usr/share/mysql/mysql.server [root@mydb mysql55rpm]# ll /usr/sbin/mysqld -rwxr-xr-x 1 root root 45012185 Mar 10  2011 /usr/sbin/mysqld [root@mydb mysql55rpm]# ps -ef|grep mysql root      4448     1  0 16:57 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/mydb.pid mysql     4527  4448  1 16:57 pts/1    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/mydb.err --pid-file=/var/lib/mysql/mydb.pid [root@mydb mysql55rpm]# diff /etc/rc.d/init.d/mysql /usr/share/mysql/mysql.server                      [root@mydb mysql55rpm]# mysql.server启动,默认使用/etc/my.cnf配置文件信息,--datadir=/mysql/mysql57/data,看到的--datadir、--pid-file都是parse_server_arguments函数指定的参数 [root@mydb]# service mysqld start [root@mydb]# ps -ef|grep mysql root      7747     1  0 21:13 pts/1    00:00:00 /bin/sh /mysql/mysql57/bin/mysqld_safe --datadir=/mysql/mysql57/data --pid-file=/mysql/mysql57/data/mydb.pid mysql     7866  7747  8 21:13 pts/1    00:00:00 /mysql/mysql57/bin/mysqld --basedir=/mysql/mysql57 --datadir=/mysql/mysql57/data --plugin-dir=/mysql/mysql57/lib/plugin --user=mysql --log-error=/mysql/mysql57/data/mydb.err --pid-file=/mysql/mysql57/data/mydb.pid mysqld_safe中的内容 mysql.server works by first doing a cd to the base directory and from there executing mysqld_safe mysql.server的工作原理是先cd进入基目录,然后执行mysqld_safe /usr/share/mysql/mysql.server中的内容 If you install MySQL on some other places than /usr/local/mysql, then you have to do one of the following things for this script to work Run this script from within the MySQL installation directory Create a /etc/my.cnf file with the following information: [mysqld] basedir=<path-to-mysql-installation-directory> and copy my_print_defaults to /usr/bin 在/etc/init.d/mysql里面修改basedir和datadir,会被my.cnf覆盖,即my.cnf中的生效而/etc/init.d/mysql中的不生效(已经实验验证过的) If you change base dir, you must also change datadir. These may get overwritten by settings in the MySQL configuration files basedir= datadir= The following variables are only set for letting mysql.server find things if test -z "$basedir" then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin else  bindir="$basedir/bin" if test -z "$datadir" then datadir=/usr/local/mysql/data else datadir="$basedir/data" parse_server_arguments() {   for arg do     case "$arg" in       --basedir=*)        --datadir=*)         --pid-file=*)        --service-startup-timeout=*)  Try to find basedir in /etc/my.cnf conf=/etc/my.cnf parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server` echo $echo_n "Starting MySQL" if test -x $bindir/mysqld_safe then #Give extra arguments to mysqld with the my.cnf file $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 & else log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)" mysql.server 脚本的主要作用就是为了方便启动和关闭mysql服务,这个脚本中需要调用的是 mysqld_safe这个脚本 在调用mysqld_safe的时候要把-datadir、-pid-file,$other_args这些参数值传入到mysqld_safe 脚本,那怎么来确定这些参数呢? 首先得知道 my_print_defaults 这个命令,这个命令就是从配置文件中读取mysql的参数值,具体可以通过my_print_defaults  --help 查看: parse_server_arguments 这个函数,其实只需要读取—basedir,--datadir,--pid-file,--service-startup-timeout这些参数 [root@mydb]# my_print_defaults --help Prints all arguments that is give to some program using the default files

相关推荐