MySQL DBA Tips Corner

     Return to the 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:

    Size of the core file mysqld should be able to create. Passed to ulimit -c
    Path to mysqld
    Name of the mysqld version in the ledir directory you want to start
    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.
    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!
    Set the timezone (the TZ) variable to the value of this parameter
    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:

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 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

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.

Last modified on
Monday, 25-Jul-2005 20:27:17 EDT
Page Count: 6958