4.3.2mysqld_safe-服务器启动脚本
    ++++++++++++++++++++
    Unix上建议使用的去启动mysqld服务器的方法;mysqld_safe增加了一些安全特性,例如当出现错误时重启服务器并向错误日志文件写入运行时间信息;
    对于mysql5.7.6来说,如果使用rpm安装,服务器的启动和关闭是操作系统管理的(systemd);这样,mysqld_safe就不安装,因为没用;
    mysqld_safe会从配置文件的[mysqld] [server] [mysqld_safe]区域读取配置选项;
    为了向后兼容,mysqld_safe也会读取[safe_mysqld]区域的配置选项,但是现在,应该使用[mysqld_safe]:
    mysqld_safe有很多选项:......
    mysqld_safe的许多选项和mysqld一样;
    如果mysqld_safe不能理解命令行中指定的选项,那么这些选项将会发送给mysqld;
    如果[mysqld_safe]组下边的选项不能被mysqld_safe理解,那么会被忽略;

    mysqld_safe tries to start an executable named mysqld. To override the default behavior and specify 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 the directory where mysqld_safe should look for the server

    选项:
    --help 显示帮助信息并退出;
    --basedir=dirname mysql的安装目录的路径;
    --core-file-size=size mysqld能够创建的核心文件的大小;这个选项的值被传递给了ulimit -c 
    --datadir=dirname 数据文件的路径;
    --defaults-extra-file=file_name 常用的配置文件之外的被读取的配置文件;在命令行中使用的话,它必须是第一个选项;如果指定的文件不存在或不能访问,服务器将退出并报错;
    --defaults-file=file_name 被读取的代替常用配置文件的文件;在命令行中使用的话,它必须是第一个选项,不然,该选项无效;
    --ledir=dirname 如果mysqld_safe 找不到服务器,使用这个选项去指定服务器的位置;
    --log-error=file_name 将错误日志写到指定文件;
    --mysqld-safe-log-timestamps 控制mysqld_safe输出日志文件里的时间戳的格式
        UTC,utc 这是默认的 (same as --log_timestamps=UTC for the server);
        SYSTEM,system 本地格式 (same as --log_timestamps=SYSTEM for the server);
        HYPHEN,hyphen (YY-MM-DD hh:mm:ss)
        LEGACY,legacy (YYMMDD hh:mm:ss)
    --malloc-lib=[lib_name] The name of the library to use for memory allocation instead of the system malloc() library
    --mysqld=prog_name 想要启动的mysql服务器程序(在ledir下)
    --mysqld-version=suffix 这个选项和--mysqld相似,但是只需要指定后缀就可以;mysql假定程序的基名是mysqld;
        例如:如果你使用的是--mysqld-version=debug,那么mysqld_safe将会启动ledir目录下的mysqld-debug程序;
                如果--mysqld-version选项的值是空,那么mysqld_safe将会启动ledir目录下的mysqld程序;
    --nice=priority 使用nice程序设置优先级;
    --no-defaults 不要读取任何配置文件;如果在命令行中指定了这个选项,那么它必须是第一个选项;
    --open-files-limit=count mysqld能够打开的文件的的数量,这个选项的值被传递给ulimit -n;
    --pid-file=file_name 进程ID文件的路径名
        In MySQL 5.7.2 and later, mysqld_safe creates a PID file named mysqld_safe.pid in the MySQL data directory when starting up (Bug #16776528).
    --plugin-dir=dir_name 插件路径;
    --port=port_num 使用TCP/IP连接的时候服务器使用的端口号;端口号必须不小于1024,除非使用root系统用户;
    --skip-kill-mysqld 启动的时候不要杀死stray(无主的,跑偏的)mysqld进程;只在Linux系统中有效;
    --socket=path 监听本地连接的时候mysql服务器使用的套接字文件;
    --syslog,--skip-syslog 前者将错误信息发送的syslog日志;后者则限制使用syslog,错误信息写到错误日志文件;
    --syslog-tag=tag 如果使用syslog记录日志的话,mysqld_safe和mysqld产生的消息将分别使用mysqld_safe和mysqld作为标识符;
        为了给标识符指定一个后缀,可以使用这个选项;那么,标识符就成了mysqld_safe-tag和mysqld-tag;
        mysql5.7.5不赞成使用这个选项来记录日志,相反,建议使用log_syslog_tag系统变量;
    --timezone=timezone Set the TZ time zone environment variable to the given option value. Consult your operating system documentation for legal time zone specification formats.
    --user={user_name|user_id} 
        Run the mysqld server as the user having the name user_name or the numeric user ID user_id.
        (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)

    The mysqld_safe script is written so that it normally can start a server that was installed from either
    a source or a binary distribution of MySQL, even though these types of distributions typically install the
    server in slightly different locations. (See Section 2.1.4, “Installation Layouts”.) mysqld_safe expects
    one of the following conditions to be true:
    1、可以找到相对于工作目录的服务和数据库(工作目录:  mysqld_safe被调用的目录)
        对于二进制安装来说,mysqld_safe在工作目录下找bin和data目录;
        对于源码安装来说,mysqld_safe在工作目录下找libexec和var目录;   
        如果你从mysql的安装目录执行mysqld_safe的话,上面的条件应该被满足;
    2、如果在工作目录的相对目录里边找不到服务和数据库,mysqld_safe将试图使用绝对路径;
        典型的路径是/usr/local/libexec和/usr/local/var; 实际的位置是编译的时候指定的;

    因为mysqld_safe试图在它自己的工作目录的相对目录下找服务和数据库,所以可以将二进制的mysql安装到任何地方,只要你在安装目录下运行mysqld_safe
        shell> cd mysql_installaion_direction
        shell> bin/mysqld_safe &

    如果在安装目录下运行mysqld_safe也失败了,那么请使用--ledir和--datadir选项指定服务和数据库所在的目录;

    mysqld_safe tries to use the sleep and date system utilities to determine how many times per
    second it has attempted to start. If these utilities are present and the attempted starts per second is
    greater than 5, mysqld_safe waits 1 full second before starting again. This is intended to prevent
    excessive CPU usage in the event of repeated failures. (Bug #11761530, Bug #54035)

    当使用mysqld_safe启动mysqld的时候,mysqld_safe将它自己和mysqld的错误日志放到同一个地方;
        有几个控制日志的选项 :--syslog,--skip-syslog,--log-error=file_name
Logo

更多推荐