MySQL DBA Tips Corner
Starting and Stopping MySQL - (Release 3.23)
by Jeff Hunter, Sr. Database Administrator
% bin/safe_mysqld --user=mysql &
% bin/mysqladmin -u root shutdown
About the safe_mysqld Wrapper Around mysqld
safe_mysqld is the recommended way to start a mysqld deamon on Unix. safe_mysqld adds some safety features such as restarting the server when an error occurs and logging runtime information to a logfile.
If you don't use --mysqld=#, or --mysqld-version=# mysqld will use an executable named mysqld-max if it exists. If not, safe_mysqld will start mysqld. This makes it very easy to test to use mysqld-max instead of mysqld; just copy mysqld-max to where you have mysqld and it will be used.
Normally one should never edit the safe_mysqld script, but instead put the options to safe_mysqld in the [safe_mysqld] section in the my.cnf file. safe_mysqld will read all options from the [mysqld], [server], and [safe_mysqld], sections from the option files.
Note that all options on the command-line to safe_mysqld are passed to mysqld. If you want to use any options in safe_mysqld that mysqld doesn't support, you must specify these in the option file.
Most of the options to safe_mysqld are the same as the options to mysqld.
safe_mysqld supports the following options:--basedir=path --core-file-size=# Size of the core file mysqld should be able to create. Passed to ulimit -c --datadir=path --defaults-extra-file=path --defaults-extra=path --err-log=path --ledir=path Path to mysqld --log=path --mysqld=mysqld-version Name of the mysqld version in the ledir directory you want to start --mysqld-version=version Similar to --mysqld=, but here you only give the suffix for mysqld. For example, if you use mysqld-version=max, safe-mysqld will start the ledir/mysqld-max version. If the argument to --mysqld-version is empty, ledir/mysqld will be used. --no-defaults --open-files-limit=# Number of files mysqld should be able to open. Passed to ulimit -n. Note that you need to start safe_mysqld as root for this work work properly! --pid-file=path --port=# --socket=path --timezone=# Set the timezone (the TZ) variable to the value of this parameter --user=# The safe_mysqld script is written so that it normally is able to start a server that was installed from either a source or a binary version of MySQL, even it these install the server in slightly different locations. safe_mysqld expects one of these conditions to be true:
- The server and databases can be found relative to the directory from which safe_mysqld is invoked. safe_mysqld looks under its working directory for bin and data directories (for binary distributions) or for libexec and var directories (for source distributions). This condition should be met if you execute safe_mysqld from your MySQL installation directory (for example, /usr/local/mysql for a binary distribution).
- If the server and databases cannot be found relative to the working directory, safe_mysqld attempts to locate them by absolute path pathnames. Typical locations are /usr/local/libexec and /usr/local/var. The actual locations are determined when the distribution was built from which safe_mysqld comes. They should be correct if MySQL was installed in a standard location.
Because safe_mysqld will try to find the server and database relative to its own working directory, you can install a binary distribution of MySQL anywhere, as long as you start safe_mysqld from the MySQL installation directory:% cd /usr/local/mysql bin/safe_mysqld &
If safe_mysqld fails, even when invoked from the MySQL installation directory, you can modify it to use the path to mysqld and the pathname options that are correct for your system. Note that if you upgrade MySQL in the future, your modified version of safe_mysqld will be overritten, so you should make a copy of your edited version that you can reinstall.
Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at firstname.lastname@example.org.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.