Table of Contents
Access denied ErrorsThis chapter covers topics that deal with administering a MySQL installation, such as configuring the server, managing user accounts, and performing backups.
The MySQL server, mysqld, is the main program that does most of the work in a MySQL installation. The server is accompanied by several related scripts that perform setup operations when you install MySQL or that are helper programs to assist you in starting and stopping the server.
This section provides an overview of the server and related programs, and information about server startup scripts. Information about configuring the server itself is given in Section 5.3, “mysqld — The MySQL Server”.
All MySQL programs take many different options. However, every
MySQL program provides a --help option that you
can use to get a description of the program's options. For
example, try mysqld --help.
You can override default options for all standard programs by specifying options on the command line or in an option file. Section 4.3, “Specifying Program Options”.
The following list briefly describes the MySQL server and server-related programs:
The SQL daemon (that is, the MySQL server). To use client programs, this program must be running, because clients gain access to databases by connecting to the server. See Section 5.3, “mysqld — The MySQL Server”.
A version of the server that includes additional features. See Section 5.1.2, “The mysqld-max Extended MySQL Server”.
A server startup script. mysqld_safe attempts to start mysqld-max if it exists, and mysqld otherwise. See Section 5.1.3, “mysqld_safe — MySQL Server Startup Script”.
A server startup script. This script is used on systems that use run directories containing scripts that start system services for particular run levels. It invokes mysqld_safe to start the MySQL server. See Section 5.1.4, “mysql.server — MySQL Server Startup Script”.
A server startup script that can start or stop multiple servers installed on the system. See Section 5.1.5, “mysqld_multi — Program for Managing Multiple MySQL Servers”.
This script creates the MySQL grant tables with default privileges. It is usually executed only once, when first installing MySQL on a system. See Section 2.9.2, “Unix Post-Installation Procedures”.
This script is used after an upgrade install operation, to update the grant tables with any changes that have been made in newer versions of MySQL. See Section 2.10.3, “Upgrading the Grant Tables”.
There are several other programs that also are run on the server host:
A utility to describe, check, optimize, and repair
MyISAM tables.
myisamchk is described in
Section 5.9.5, “myisamchk — MyISAM Table-Maintenance Utility”.
This program makes a binary release of a compiled MySQL.
This could be sent by FTP to
/pub/mysql/upload/ on
ftp.mysql.com for the convenience of
other MySQL users.
The MySQL bug reporting script. It can be used to send a bug report to the MySQL mailing list. (You can also visit http://bugs.mysql.com/ to file a bug report online. See Section 1.7.1.3, “How to Report Bugs or Problems”.)
A MySQL-Max server is a version of the mysqld MySQL server that has been built to include additional features.
The distribution to use depends on your platform:
For Windows, MySQL binary distributions include both the
standard server (mysqld.exe) and the
MySQL-Max server (mysqld-max.exe), so you
need not get a special distribution. Just use a regular
Windows distribution, available at
http://dev.mysql.com/downloads/. See
Section 2.3, “Installing MySQL on Windows”.
For Linux, if you install MySQL using RPM distributions, use
the regular MySQL-server RPM first to
install a standard server named mysqld.
Then use the MySQL-Max RPM to install a
server named mysqld-max. The
MySQL-Max RPM presupposes that you have
installed the regular server RPM. See
Section 2.4, “Installing MySQL on Linux” for more information on the
Linux RPM packages.
All other MySQL-Max distributions contain a single server that is named mysqld but that has the additional features included.
You can find the MySQL-Max binaries on the MySQL AB Web site at http://dev.mysql.com/downloads/.
MySQL AB builds the MySQL-Max servers by using the following configure options:
--with-server-suffix=-max
This option adds a -max suffix to the
mysqld version string.
--with-innodb
This option enables support for the InnoDB storage engine. MySQL-Max servers always include InnoDB support. From MySQL 4.0 onwards, InnoDB is included by default in all binary distributions, so you do not need a MySQL-Max server merely to obtain InnoDB support.
--with-bdb
This option enables support for the Berkeley DB (BDB) storage engine.
--with-blackhole-storage-engine
This option enables support for the
BLACKHOLE storage engine.
USE_SYMDIR
This define is enabled to turn on database symbolic link support for Windows. Symbolic link support is available for all Windows servers, so a Max server is not needed to take advantage of this feature.
--with-ndbcluster
This option enables support for the NDB Cluster storage engine. Currently (as of 5.0.16), Cluster is supported on Linux, Solaris, and Mac OS X only. Some users have reported success in using MySQL Cluster built from source on BSD operating systems, but these are not officially supported at this time.
MySQL-Max binary distributions are a convenience for those who wish to install precompiled programs. If you build MySQL using a source distribution, you can build your own Max-like server by enabling the same features at configuration time that the MySQL-Max binary distributions are built with.
MySQL-Max servers include the BerkeleyDB (BDB) storage engine whenever possible, but not all platforms support BDB.
MySQL-Max servers for Solaris, Mac OS X, and Linux (on most
platforms) include support for the NDB Cluster storage engine.
Note that the server must be started with the
ndbcluster option in order to run the server
as part of a MySQL Cluster. (For details, see
Section 15.4, “MySQL Cluster Configuration”.)
The following table shows on which platforms MySQL-Max binaries include support for BDB and/or NDB Cluster:
| System | BDB Support | NDB Support |
| AIX 4.3 | N | N |
| HP-UX 11.0 | N | N |
| Linux-Alpha | N | Y |
| Linux-IA-64 | N | N |
| Linux-Intel | Y | Y |
| Mac OS X | N | N |
| NetWare | N | N |
| SCO OSR5 | Y | N |
| Solaris-SPARC | Y | Y |
| Solaris-Intel | N | Y |
| UnixWare | Y | N |
| Windows NT/2000/XP | Y | N |
To find out which storage engines your server supports, issue the following statement:
mysql> SHOW ENGINES;
+------------+---------+----------------------------------------------------------------+
| Engine | Support | Comment |
+------------+---------+----------------------------------------------------------------+
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables |
| HEAP | YES | Alias for MEMORY |
| MERGE | YES | Collection of identical MyISAM tables |
| MRG_MYISAM | YES | Alias for MERGE |
| ISAM | NO | Obsolete storage engine, now replaced by MyISAM |
| MRG_ISAM | NO | Obsolete storage engine, now replaced by MERGE |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys |
| INNOBASE | YES | Alias for INNODB |
| BDB | YES | Supports transactions and page-level locking |
| BERKELEYDB | YES | Alias for BDB |
| NDBCLUSTER | NO | Clustered, fault-tolerant, memory-based tables |
| NDB | NO | Alias for NDBCLUSTER |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | YES | Archive storage engine |
| CSV | NO | CSV storage engine |
| FEDERATED | YES | Federated MySQL storage engine |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) |
+------------+---------+----------------------------------------------------------------+
18 rows in set (0.00 sec)
(See also Section 13.5.4.8, “SHOW ENGINES Syntax”.)
You can also use the following statement instead of
SHOW ENGINES, and check the value of the
variable for the storage engine in which you are interested:
mysql> SHOW VARIABLES LIKE 'have%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| have_archive | YES |
| have_bdb | YES |
| have_blackhole_engine | YES |
| have_compress | YES |
| have_crypt | NO |
| have_csv | NO |
| have_example_engine | NO |
| have_federated_engine | YES |
| have_geometry | YES |
| have_innodb | YES |
| have_isam | NO |
| have_ndbcluster | NO |
| have_openssl | YES |
| have_query_cache | YES |
| have_raid | NO |
| have_rtree_keys | YES |
| have_symlink | YES |
+-----------------------+-------+
17 rows in set (0.06 sec)
The precise output from these SHOW commands
will vary according to the MySQL version used (and the features
which are enabled). The values in the second column indicate the
server's level of support for each feature, as shown here:
| Value | Meaning |
YES | The feature is supported and is active. |
NO | The feature is not supported. |
DISABLED | The feature is supported but has been disabled. |
A value of NO means that the server was
compiled without support for the feature, so it cannot be
activated at runtime.
A value of DISABLED occurs either because the
server was started with an option that disables the feature, or
because not all options required to enable it were given. In the
latter case, the
error log file should contain a reason indicating why the option
is disabled.
host_name.err
You might also see DISABLED for the
InnoDB or BDB storage
engines if the server was compiled to support them, but was
started with the --skip-innodb or
--skip-bdb options at runtime. For the
NDB Cluster storage engine,
DISABLED means the the server was compiled
with support for MySQL Cluster, but was not started with the
--ndb-cluster option.
All MySQL servers support MyISAM tables,
because MyISAM is the default storage engine.
mysqld_safe is the recommended way to start a mysqld server on Unix and NetWare. mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file. NetWare-specific behaviors are listed later in this section.
Note: To preserve backward compatibility with older versions of MySQL, MySQL binary distributions still include safe_mysqld as a symbolic link to mysqld_safe. However, you should not rely on this as it almost certainly will be removed in future.
By default, mysqld_safe tries to start an executable named mysqld-max if it exists, or mysqld otherwise. Be aware of the implications of this behavior:
On Linux, the MySQL-Max RPM relies on
this mysqld_safe behavior. The RPM
installs an executable named
mysqld-max, which causes
mysqld_safe to automatically use that
executable from that point on.
If you install a MySQL-Max distribution that includes a server named mysqld-max, then upgrade later to a non-Max version of MySQL, mysqld_safe still attempts to run the old mysqld-max server. If you perform such an upgrade, you should manually remove the old mysqld-max server to ensure that mysqld_safe runs the new mysqld server.
To override the default behavior and specify explicitly
which server you want to run, specify a
--mysqld or
--mysqld-version option to
mysqld_safe.
Many of the options to mysqld_safe are the same as the options to mysqld. See Section 5.3.1, “mysqld Command-Line Options”.
All options specified to mysqld_safe on
the command line are passed to mysqld. If
you want to use any options that are specific to
mysqld_safe and that
mysqld doesn't support, do not specify
them on the command line. Instead, list them in the
[mysqld_safe] group of an option file.
See Section 4.3.2, “Using Option Files”.
mysqld_safe reads all options from the
[mysqld], [server],
and [mysqld_safe] sections in option
files. For backward compatibility, it also reads
[safe_mysqld] sections, although you
should rename such sections to
[mysqld_safe] in MySQL 5.0
installations.
mysqld_safe supports the following options:
--help
Display a help message and exit. (Added in MySQL 5.0.3)
--autoclose
(NetWare only) On NetWare, mysqld_safe provides a screen presence. When you unload (shut down) the mysqld_safe NLM, the screen does not by default go away. Instead, it prompts for user input:
*<NLM has terminated; Press any key to close the screen>*
If you want NetWare to close the screen automatically
instead, use the --autoclose option to
mysqld_safe.
--basedir=
path
The path to the MySQL installation directory.
--core-file-size=
size
The size of the core file mysqld should be able to create. The option value is passed to ulimit -c.
--datadir=
path
The path to the data directory.
--defaults-extra-file=
path
The name of an option file to be read in addition to the usual option files. If given, this option must be first.
--defaults-file=
path
The name of an option file to be read instead of the usual option files. If given, this option must be first.
--ledir=
path
The path to the directory containing the mysqld program. Use this option to explicitly indicate the location of the server.
--log-error=
path
Write the error log to the given file. See Section 5.11.1, “The Error Log”.
--mysqld=
prog_name
The name of the server program (in the
ledir directory) that you want to
start. This option is needed if you use the MySQL binary
distribution but have the data directory outside of the
binary distribution.
--mysqld-version=
suffix
This option is similar to the --mysqld
option, but you specify only the suffix for the server
program name. The basename is assumed to be
mysqld. For example, if you use
--mysqld-version=max,
mysqld_safe starts the
mysqld-max program in the
ledir directory. If the argument to
--mysqld-version is empty,
mysqld_safe uses
mysqld in the
ledir directory.
--nice=
priority
Use the nice program to set the
server's scheduling priority to the given value.
--no-defaults
Do not read any option files. If given, this option must be first.
--open-files-limit=
count
The number of files mysqld should be
able to open. The option value is passed to
ulimit -n. Note that you need to
start mysqld_safe as
root for this to work properly!
--pid-file=
path
The path to the process ID file.
--port=
port_num
The port number to use when listening for TCP/IP
connections. The port number must be
1024 or higher unless MySQL is run as
the root system user.
--skip-character-set-client-handshake
Ignore character set information sent by the client and use the default server character set. (This option makes MySQL behave like MySQL 4.0.)
--socket=
path
The Unix socket file to use for local connections.
--timezone=
zone
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.)
When executing mysqld_safe, the
--defaults-file or
--defaults-extra-option must be given
first, or the option file will not be used. For example,
this command will not use the named option file:
mysqld_safe --port=port_num--defaults-file=file_name
Instead, use the following command:
mysqld_safe --defaults-file=file_name--port=port_num
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.5, “Installation Layouts”.) mysqld_safe expects one of the following conditions to be true:
The server and databases can be found relative to the
directory from which mysqld_safe is
invoked. For binary distributions,
mysqld_safe looks under its working
directory for bin and
data directories. For source
distributions, it looks for libexec
and var directories. This condition
should be met if you execute
mysqld_safe 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, mysqld_safe
attempts to locate them by absolute pathnames. Typical
locations are /usr/local/libexec
and /usr/local/var. The actual
locations are determined from the values configured into
the distribution at the time it was built. They should
be correct if MySQL is installed in the location
specified at configuration time.
Because mysqld_safe tries to find the server and databases relative to its own working directory, you can install a binary distribution of MySQL anywhere, as long as you run mysqld_safe from the MySQL installation directory:
shell>cd mysql_installation_directoryshell>bin/mysqld_safe &
If mysqld_safe fails, even when invoked
from the MySQL installation directory, you can specify the
--ledir and --datadir
options to indicate the directories in which the server and
databases are located on your system.
Normally, you should not edit the
mysqld_safe script. Instead, configure
mysqld_safe by using command-line options
or options in the [mysqld_safe] section
of a my.cnf option file. In rare cases,
it might be necessary to edit mysqld_safe
to get it to start the server properly. However, if you do
this, your modified version of
mysqld_safe might be overwritten if you
upgrade MySQL in the future, so you should make a copy of
your edited version that you can reinstall.
On NetWare, mysqld_safe is a NetWare Loadable Module (NLM) that is ported from the original Unix shell script. It does the following:
Runs a number of system and option checks.
Runs a check on MyISAM tables.
Provides a screen presence for the MySQL server.
Starts mysqld, monitors it, and restarts it if it terminates in error.
Sends error messages from mysqld to
the
file in the data directory.
host_name.err
Sends mysqld_safe screen output to
the
file in the data directory.
host_name.safe
MySQL distributions on Unix include a script named mysql.server. It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the Mac OS X Startup Item for MySQL.
mysql.server can be found in the
support-files directory under your
MySQL installation directory or in a MySQL source tree.
If you use the Linux server RPM package
(MySQL-server-),
the mysql.server script will be installed
in the VERSION.rpm/etc/init.d directory with the
name mysql. You need not install it
manually. See Section 2.4, “Installing MySQL on Linux” for more
information on the Linux RPM packages.
Some vendors provide RPM packages that install a startup script under a different name such as mysqld.
If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install it manually. Instructions are provided in Section 2.9.2.2, “Starting and Stopping MySQL Automatically”.
mysql.server reads options from the
[mysql.server] and
[mysqld] sections of option files. (For
backward compatibility, it also reads
[mysql_server] sections, although you
should rename such sections to
[mysql.server] when using MySQL
5.0.)
mysqld_multi is meant for managing several mysqld processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status.
The program searches for groups named
[mysqld in
N]my.cnf (or in the file named by the
--config-file option).
N can be any positive integer.
This number is referred to in the following discussion as
the option group number, or GNR.
Group numbers distinguish option groups from one another and
are used as arguments to mysqld_multi to
specify which servers you want to start, stop, or obtain a
status report for. Options listed in these groups are the
same that you would use in the [mysqld]
group used for starting mysqld. (See, for
example, Section 2.9.2.2, “Starting and Stopping MySQL Automatically”.) However, when
using multiple servers it is necessary that each one use its
own value for options such as the Unix socket file and
TCP/IP port number. For more information on which options
must be unique per server in a multiple-server environment,
see Section 5.12, “Running Multiple MySQL Servers on the Same Machine”.
To invoke mysqld_multi, use the following syntax:
shell> mysqld_multi [options] {start|stop|report} [GNR[,GNR] ...]
start, stop, and
report indicate which operation you want
to perform. You can perform the designated operation on a
single server or multiple servers, depending on the
GNR list that follows the option
name. If there is no list, mysqld_multi
performs the operation for all servers in the option file.
Each GNR value represents an
option group number or range of group numbers. The value
should be the number at the end of the group name in the
option file. For example, the GNR
for a group named [mysqld17] is
17. To specify a range of numbers,
separate the first and last numbers by a dash. The
GNR value
10-13 represents groups
[mysqld10] through
[mysqld13]. Multiple groups or group
ranges can be specified on the command line, separated by
commas. There must be no whitespace characters (spaces or
tabs) in the GNR list; anything
after a whitespace character is ignored.
This command starts a single server using option group
[mysqld17]:
shell> mysqld_multi start 17
This command stops several servers, using option groups
[mysql8] and
[mysqld10] through
[mysqld13]:
shell> mysqld_multi stop 8,10-13
For an example of how you might set up an option file, use this command:
shell> mysqld_multi --example
mysqld_multi supports the following options:
Specify the name of an alternative option file. This
affects where mysqld_multi looks for
[mysqld
option groups. Without this option, all options are read
from the usual N]my.cnf file. The
option does not affect where
mysqld_multi reads its own options,
which are always taken from the
[mysqld_multi] group in the usual
my.cnf file.
Display a sample option file.
Display a help message and exit.
Specify the name of the log file. If the file exists, log output is appended to it.
The mysqladmin binary to be used to stop servers.
The mysqld binary to be used. Note
that you can specify mysqld_safe as
the value for this option also. The options are passed
to mysqld. Just make sure that you
have the directory where mysqld is
located in your PATH environment
variable setting or fix mysqld_safe.
Print log information to stdout rather than to the log file. By default, output goes to the log file.
The password of the MySQL account to use when invoking mysqladmin. Note that the password value is not optional for this option, unlike for other MySQL programs.
Disable warnings.
Connect to each MySQL server via the TCP/IP port instead
of the Unix socket file. (If a socket file is missing,
the server might still be running, but accessible only
via the TCP/IP port.) By default, connections are made
using the Unix socket file. This option affects
stop and report
operations.
The username of the MySQL account to use when invoking mysqladmin.
Be more verbose.
Display version information and exit.
Some notes about mysqld_multi:
Make sure that the MySQL account used for stopping the
mysqld servers (with the
mysqladmin program) has the same
username and password for each server. Also, make sure
that the account has the SHUTDOWN
privilege. If the servers that you want to manage have
many different usernames or passwords for the
administrative accounts, you might want to create an
account on each server that has the same username and
password. For example, you might set up a common
multi_admin account by executing the
following commands for each server:
shell>mysql -u root -S /tmp/mysql.sock -pmysql>root_passwordGRANT SHUTDOWN ON *.*->TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
See Section 5.7.2, “How the Privilege System Works”. You have to do this
for each mysqld server. Change the
connection parameters appropriately when connecting to
each one. Note that the host part of the account name
must allow you to connect as
multi_admin from the host where you
want to run mysqld_multi.
The --pid-file option is very important
if you are using mysqld_safe to start
mysqld (for example,
--mysqld=mysqld_safe) Every
mysqld should have its own process ID
file. The advantage of using
mysqld_safe instead of
mysqld is that
mysqld_safe “guards” its
mysqld process and restarts it if the
process terminates due to a signal sent using
kill -9 or for other reasons, such as
a segmentation fault. Please note that the
mysqld_safe script might require that
you start it from a certain place. This means that you
might have to change location to a certain directory
before running mysqld_multi. If you
have problems starting, please see the
mysqld_safe script. Check especially
the lines:
---------------------------------------------------------------- MY_PWD=`pwd` # Check if we are starting this relative (for the binary release) if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \ -x ./bin/mysqld ----------------------------------------------------------------
See Section 5.1.3, “mysqld_safe — MySQL Server Startup Script”. The test performed by these lines should be successful, or you might encounter problems.
The Unix socket file and the TCP/IP port number must be different for every mysqld.
You might want to use the --user option
for mysqld, but in order to do this
you need to run the mysqld_multi
script as the Unix root user. Having
the option in the option file doesn't matter; you just
get a warning if you are not the superuser and the
mysqld processes are started under
your own Unix account.
Important: Make sure that the data directory is fully accessible to the Unix account that the specific mysqld process is started as. Do not use the Unix root account for this, unless you know what you are doing.
Most important: Before using mysqld_multi be sure that you understand the meanings of the options that are passed to the mysqld servers and why you would want to have separate mysqld processes. Beware of the dangers of using multiple mysqld servers with the same data directory. Use separate data directories, unless you know what you are doing. Starting multiple servers with the same data directory does not give you extra performance in a threaded system. See Section 5.12, “Running Multiple MySQL Servers on the Same Machine”.
The following example shows how you might set up an option
file for use with mysqld_multi. The first
and fifth
[mysqld
group were intentionally left out from the example to
illustrate that you can have “gaps” in the
option file. This gives you more flexibility. The order in
which the mysqld programs are started or
stopped depends on the order in which they appear in the
option file.
N]
# This file should probably be in your home dir (~/.my.cnf) # or /etc/my.cnf # Version 2.1 by Jani Tolonen [mysqld_multi] mysqld = /usr/local/bin/mysqld_safe mysqladmin = /usr/local/bin/mysqladmin user = multi_admin password = multipass [mysqld2] socket = /tmp/mysql.sock2 port = 3307 pid-file = /usr/local/mysql/var2/hostname.pid2 datadir = /usr/local/mysql/var2 language = /usr/local/share/mysql/english user = john [mysqld3] socket = /tmp/mysql.sock3 port = 3308 pid-file = /usr/local/mysql/var3/hostname.pid3 datadir = /usr/local/mysql/var3 language = /usr/local/share/mysql/swedish user = monty [mysqld4] socket = /tmp/mysql.sock4 port = 3309 pid-file = /usr/local/mysql/var4/hostname.pid4 datadir = /usr/local/mysql/var4 language = /usr/local/share/mysql/estonia user = tonu [mysqld6] socket = /tmp/mysql.sock6 port = 3311 pid-file = /usr/local/mysql/var6/hostname.pid6 datadir = /usr/local/mysql/var6 language = /usr/local/share/mysql/japanese user = jani
The MySQL Instance Manager (IM) is a daemon running on a TCP/IP port, which serves for monitoring and management of MySQL Database Server instances. MySQL Instance Manager is available for Unix-like operating systems, and also on Windows as of MySQL 5.0.13.
MySQL Instance Manager is included in MySQL distributions from
version 5.0.3, and can be used in place of the
mysqld_safe script to start and stop the
MySQL Server, even from a remote
host. MySQL Instance Manager also implements the
functionality (and most of the syntax) of the
mysqld_multi script. A more detailed
description of MySQL Instance Manager follows.
Normally, the MySQL Database Server is started with the
mysql.server script, which usually resides
in the /etc/init.d/ folder. In MySQL 5.0.3
this script invokes mysqlmanager (the MySQL
Instance Manager binary) to start MySQL. (In prior versions of
MySQL the mysqld_safe script is used for
this purpose.) Starting from MySQL 5.0.4 the behavior of the
init script was changed again to incorporate both setup
schemes. In version 5.0.4, the init startup script uses the
old scheme (invoking mysqld_safe) by
default, but one can set the
use_mysqld_safe variable in the script to
0 (zero) in order to use the MySQL Instance
Manager to start a server.
The Instance Manager's behavior in this case depends on the
options given in the MySQL configuration file. If there is no
configuration file, the MySQL Instance Manager creates an
instance named mysqld and attempts to start
it with default (compiled-in) configuration values. This means
that the IM cannot guess the placement of
mysqld if it is not installed in the
default location. If you have installed the MySQL server in a
non-standard location you should use a configuration file. See
Section 2.1.5, “Installation Layouts”.
If there is a configuration file, the IM will parse the
configuration file in search of [mysqld]
sections (E.g. [mysqld],
[mysqld1], [mysqld2],
etc.) Each such section specifies an instance. At startup the
IM will start all found instances. The IM stops all instances
at shutdown by default.
Note that there is a special option
mysqld-path (mysqld-path =
)
which is recognized only by the IM. Use this variable to let
the IM know where the mysqld binary
resides. You should also set path-to-mysqld-binarybasedir and
datadir options for the server.
The typical startup/shutdown cycle for a MySQL server with the MySQL Instance Manager enabled is as follows:
The MySQL Instance Manager is started with /etc/init.d/mysql script.
The MySQL Instance Manager starts all instances and monitors them.
If a server instance fails the MySQL Instance Manager restarts it.
If the MySQL Instance Manager is shut down (for instance with the /etc/init.d/mysql stop command), all instances are shut down by the MySQL Instance Manager.
Communication with the MySQL Instance Manager is handled using the MySQL client-server protocol. As such, you can connect to the IM using the standard mysql client program, as well as the MySQL C API. The IM supports the version of the MySQL client-server protocol used by the client tools and libraries distributed along with mysql-4.1 or later.
The IM stores its user information in a password file. Default
placement for the password file is
/etc/mysqlmanager.passwd
Password entries look like the following:
petr:*35110DC9B4D8140F5DE667E28C72DD2597B5C848
To generate such an entry one should invoke IM with the
--passwd option. Then the output can be
redirected to the
/etc/mysqlmanager.passwd file to add a
new user. A sample command is given below.
./mysqlmanager --passwd >> /etc/mysqlmanager.passwd Creating record for new user. Enter user name: mike Enter password: <password> Re-type password: <password>
The following line is added to
/etc/mysqlmanager.passwd:
mike:*00A51F3F48415C7D4E8908980D443C29C69B60C9
If there are no entries in the
/etc/mysqlmanager.passwd file one cannot
connect to the IM.
The MySQL Instance Manager supports a number of command line options. A brief listing is available by executing the ./mysqlmanager --help command. The following options are available:
--help, -?
Display the help message and exit.
--bind-address=
name
Bind address to use for connections.
--default-mysqld-path=
name
On Unix, where to look for the MySQL Server binary, if no
path was provided in the instance section. Example:
default-mysqld-path = /usr/sbin/mysqld
--defaults-file=
file_name
Read Instance Manager and MySQL Server settings from the given file. All configuration changes by the Instance Manager will be made to this file. This should be used only as the first option to Instance Manager.
--install
On Windows, install Instance Manager as a Windows service. This option was added in MySQL 5.0.11.
--log=
name
The path to the IM log file. This is used with the --run-as-service option.
--monitoring-interval=
seconds
Interval to monitor instances in seconds. Instance manager
will try to connect to each of monitored instances to
check whether they are alive/not hanging. In the case of a
failure IM will perform several (in fact many) attempts to
restart the instance. One can disable this behavior for
particular instances with the
nonguarded option in the appropriate
instance section. If no value was given, the default of 20
seconds will be used.
--passwd, -P
Prepare entry for passwd file and exit.
--password-file=
name
Look for the Instance Manager users and passwords in this
file. The default file is
/etc/mysqlmanager.passwd.
--pid-file=
name
The process ID file to use. By default, this file is named
mysqlmanager.pid.
--port=
port_num
The port number to use for connections. (The default port number, assigned by IANA, is 2273).
--print-defaults
Print the current defaults and exit. This should be used only as the first option to Instance Manager.
--remove
On Windows, removes Instance Manager as a Windows service.
This assumes that Instance Manager has been run with
--install previously. This option was
added in MySQL 5.0.11.
--run-as-service
Daemonize and start the angel process. The angel process is simple and unlikely to crash. It will restart the IM itself in case of a failure.
--socket=
name
On Unix, the socket file to use for the connection. By
default, the file is named
/tmp/mysqlmanager.sock.
--standalone
On Windows, run Instance Manager in standalone mode. This option was added in MySQL 5.0.13.
--user=
name
Username to start and run the mysqlmanager under. It is recommended to run mysqlmanager under the same user account used to run the mysqld server.
--version, -V
Output version information and exit.
Instance Manager uses the standard my.cnf
file. It uses the [manager] section to read
options for itself and the [mysqld]
sections to create instances. The [manager]
section contains any of the options listed above. An example
[manager] section is given below:
# MySQL Instance Manager options section [manager] default-mysqld-path = /usr/local/mysql/libexec/mysqld socket=/tmp/manager.sock pid-file=/tmp/manager.pid password-file = /home/cps/.mysqlmanager.passwd monitoring-interval = 2 port = 1999 bind-address = 192.168.1.5
Prior to MySQL 5.0.10, the MySQL Instance Manager read the
same configuration files as the MySQL Server, including
/etc/my.cnf,
~/.my.cnf, etc. As of MySQL 5.0.10, the
MySQL Instance Manager reads and manages the
/etc/my.cnf file only on Unix. On
Windows, MySQL Instance Manager reads the
my.ini file in the directory where
Instance Manager is installed. The default option file
location can be changed with the
--defaults-file=
option.
file_name
Instance sections specify options given to each instance at startup. These are mainly common MySQL server options, but there are some IM-specific options:
mysqld-path =
<path-to-mysqld-binary>
The path to the mysqld server binary.
shutdown-delay =
seconds
The number of seconds IM should wait for the instance to
shut down. The default is 35 seconds. After the delay
expires, the IM assumes that the instance is hanging and
attempts to kill -9 it. If you use
InnoDB with large tables, you should increase this value.
nonguarded
This option should be set if you want to disable IM monitoring functionality for a certain instance.
Several sample instance sections are given below.
[mysqld] mysqld-path=/usr/local/mysql/libexec/mysqld socket=/tmp/mysql.sock port=3307 server_id=1 skip-stack-trace core-file skip-bdb log-bin log-error log=mylog log-slow-queries [mysqld2] nonguarded port=3308 server_id=2 mysqld-path= /home/cps/mysql/trees/mysql-5.0/sql/mysqld socket = /tmp/mysql.sock5 pid-file = /tmp/hostname.pid5 datadir= /home/cps/mysql_data/data_dir1 language=/home/cps/mysql/trees/mysql-5.0/sql/share/english log-bin log=/tmp/fordel.log
Once you've set up a password file for the MySQL Instance Manager and the IM is running, you can connect to it. You can use the mysql client tool connect through a standard MySQL API. Below goes the list of commands the MySQL Instance Manager currently accepts, with samples.
START INSTANCE <instance_name>
This command will attempt to start an instance:
mysql> START INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)
STOP INSTANCE <instance_name>
This will attempt to stop an instance:
mysql> STOP INSTANCE mysqld4;
Query OK, 0 rows affected (0,00 sec)
SHOW INSTANCES
Show the names of all loaded instances:
mysql> show instances;
+---------------+---------+
| instance_name | status |
+---------------+---------+
| mysqld3 | offline |
| mysqld4 | online |
| mysqld2 | offline |
+---------------+---------+
3 rows in set (0,04 sec)
SHOW INSTANCE STATUS
<instance_name>
Show the status and the version info of selected instance:
mysql> SHOW INSTANCE STATUS mysqld3;
+---------------+--------+---------+
| instance_name | status | version |
+---------------+--------+---------+
| mysqld3 | online | unknown |
+---------------+--------+---------+
1 row in set (0.00 sec)
SHOW INSTANCE OPTIONS
<instance_name>
Show options used by an instance:
mysql> SHOW INSTANCE OPTIONS mysqld3;
+---------------+---------------------------------------------------+
| option_name | value |
+---------------+---------------------------------------------------+
| instance_name | mysqld3 |
| mysqld-path | /home/cps/mysql/trees/mysql-4.1/sql/mysqld |
| port | 3309 |
| socket | /tmp/mysql.sock3 |
| pid-file | hostname.pid3 |
| datadir | /home/cps/mysql_data/data_dir1/ |
| language | /home/cps/mysql/trees/mysql-4.1/sql/share/english |
+---------------+---------------------------------------------------+
7 rows in set (0.01 sec)
SHOW <instance_name> LOG FILES
The command provides a listing of all log files used by
the instance. The result set contains the path to the log
file and the log file size. If no log file path is
specified in the configuration file (i.e.
log=/var/mysql.log), the IM tries to
guess its placement. If the IM is unable to guess the
logfile placement you should specify the log file location
explicitly.
mysql> SHOW mysqld LOG FILES;
+-------------+------------------------------------+----------+
| Logfile | Path | Filesize |
+-------------+------------------------------------+----------+
| ERROR LOG | /home/cps/var/mysql/owlet.err | 9186 |
| GENERAL LOG | /home/cps/var/mysql/owlet.log | 471503 |
| SLOW LOG | /home/cps/var/mysql/owlet-slow.log | 4463 |
+-------------+------------------------------------+----------+
3 rows in set (0.01 sec)
SHOW <instance_name> LOG {ERROR | SLOW |
GENERAL} size[,offset_from_end]
This command retrieves a portion of the specified log
file. Because most users are interested in the latest log
messages, the size parameter defines
the number of bytes you would like to retrieve starting
from the log end. You can retrieve data from the middle of
the log file by specifying the optional
offset_from_end parameter. The
following example retrieves 21 bytes of data, starting 23
bytes from the end of the log file and ending 2 bytes from
the end of the log file:
mysql> SHOW mysqld LOG GENERAL 21, 2;
+---------------------+
| Log |
+---------------------+
| using password: YES |
+---------------------+
1 row in set (0.00 sec)
SET
instance_name.option_name=option_value
This commands edits the specified instance's configuration
file to change/add instance options. The IM assumes that
the configuration file is located at
/etc/my.cnf. You should check that
the file exists and has appropriate permissions.
mysql> SET mysqld2.port=3322;
Query OK, 0 rows affected (0.00 sec)
Changes made to the configuration file will not take
effect until the MySQL server is restarted. In addition,
these changes are not stored in the instance manager's
local cache of instance settings until a FLUSH
INSTANCES command is executed.
UNSET instance_name.option_name
This command removes an option from an instance's configuration file.
mysql> UNSET mysqld2.port;
Query OK, 0 rows affected (0.00 sec)
Changes made to the configuration file will not take
effect until the MySQL server is restarted. In addition,
these changes are not stored in the instance manager's
local cache of instance settings until a FLUSH
INSTANCES command is executed.
FLUSH INSTANCES
This command forces IM to reread the configuration file and to refresh internal structures. This command should be performed after editing the configuration file. This command does not restart instances:
mysql> FLUSH INSTANCES;
Query OK, 0 rows affected (0.04 sec)
mysqld is the MySQL server. The following discussion covers these MySQL server configuration topics:
Startup options that the server supports
How to set the server SQL mode
Server system variables
Server status variables
When you start the mysqld server, you can specify program options using any of the methods described in Section 4.3, “Specifying Program Options”. The most common methods are to provide options in an option file or on the command line. However, in most cases it is desirable to make sure that the server uses the same options each time it runs. The best way to ensure this is to list them in an option file. See Section 4.3.2, “Using Option Files”.
mysqld reads options from the
[mysqld] and [server]
groups. mysqld_safe reads options from the
[mysqld], [server],
[mysqld_safe], and
[safe_mysqld] groups.
mysql.server reads options from the
[mysqld] and
[mysql.server] groups. An embedded MySQL
server usually reads options from the
[server], [embedded],
and
[
groups, where xxxxx_SERVER]xxxxx is the name of
the application into which the server is embedded.
mysqld accepts many command-line options. For a brief list, execute mysqld --help. To see the full list, use mysqld --verbose --help.
The following list shows some of the most common server options. Additional options are described elsewhere:
Options that affect security: See Section 5.6.3, “Startup Options for mysqld Concerning Security”.
SSL-related options: See Section 5.8.7.6, “SSL Command-Line Options”.
Binary log control options: See Section 5.11.3, “The Binary Log”.
Replication-related options: See Section 6.8, “Replication Startup Options”.
Options specific to particular storage engines: See
Section 14.1.1, “MyISAM Startup Options”,
Section 14.5.3, “BDB Startup Options”, and
Section 14.2.4, “InnoDB Startup Options”.
You can also set the value of a server system variable by using the variable name as an option, as described later in this section.
--help, -?
Display a short help message and exit. Use both the
--verbose and --help
options to see the full message.
--allow-suspicious-udfs
This option controls whether user-defined functions that
have only an xxx symbol for the main
function can be loaded. By default, the option is off and
only UDFs that have at least one auxiliary symbol can be
loaded. This prevents attempts at loading functions from
shared object files other than those containing legitimate
UDFs. This option was added in version 5.0.3. See
Section 24.2.3.6, “User-Defined Function Security Precautions”.
--ansi
Use standard (ANSI) SQL syntax instead of MySQL syntax.
See Section 1.8.3, “Running MySQL in ANSI Mode”. For more precise control
over the server SQL mode, use the
--sql-mode option instead.
--basedir=
path, -b
path
The path to the MySQL installation directory. All paths are usually resolved relative to this.
--bind-address=
IP
The IP address to bind to.
--bootstrap
This option is used by the mysql_install_db script to create the MySQL privilege tables without having to start a full MySQL server.
--console
Write error log messages to stderr and
stdout even if
--log-error is specified. On Windows,
mysqld does not close the console
screen if this option is used.
--character-sets-dir=
path
The directory where character sets are installed. See Section 5.10.1, “The Character Set Used for Data and Sorting”.
--chroot=
path
Put the mysqld server in a closed
environment during startup by using the
chroot() system call. This is a
recommended security measure. Note that use of this option
somewhat limits LOAD DATA INFILE and
SELECT ... INTO OUTFILE.
--character-set-server=
charset
Use charset as the default
server character set. See
Section 5.10.1, “The Character Set Used for Data and Sorting”.
--core-file
Write a core file if mysqld dies. For
some systems, you must also specify the
--core-file-size option to
mysqld_safe. See
Section 5.1.3, “mysqld_safe — MySQL Server Startup Script”. Note that on some systems,
such as Solaris, you do not get a core file if you are
also using the --user option.
--collation-server=
collation
Use collation as the default
server collation. See Section 5.10.1, “The Character Set Used for Data and Sorting”.
--datadir=
path, -h
path
The path to the data directory.
--debug[=,
debug_options]-#
[
debug_options]
If MySQL is configured with --with-debug,
you can use this option to get a trace file of what
mysqld is doing. The
debug_options string often is
'd:t:o,.
See Section E.1.2, “Creating Trace Files”.
file_name'
(DEPRECATED)
--default-character-set=
charset
Use charset as the default
character set. This option is deprecated in favor of
--character-set-server. See
Section 5.10.1, “The Character Set Used for Data and Sorting”.
--default-collation=
collation
Use collation as the default
collation. This option is deprecated in favor of
--collation-server. See
Section 5.10.1, “The Character Set Used for Data and Sorting”.
--default-storage-engine=
type
This option is a synonym for
--default-table-type.
--default-table-type=
type
Set the default table type for tables. See Chapter 14, Storage Engines and Table Types.
--default-time-zone=
type
Set the default server time zone. This option sets the
global time_zone system variable. If
this option is not given, the default time zone is the
same as the system time zone (given by the value of the
system_time_zone system variable.
--delay-key-write[= OFF | ON | ALL]
How the DELAYED KEYS option should be
used. Delayed key writing causes key buffers not to be
flushed between writes for MyISAM
tables. OFF disables delayed key
writes. ON enables delayed key writes
for those tables that were created with the
DELAYED KEYS option.
ALL delays key writes for all
MyISAM tables. See
Section 7.5.2, “Tuning Server Parameters”. See
Section 14.1.1, “MyISAM Startup Options”.
Note: If you set this
variable to ALL, you should not use
MyISAM tables from within another
program (such as from another MySQL server or with
myisamchk) when the table is in use.
Doing so leads to index corruption.
--des-key-file=
file_name
Read the default keys used by
DES_ENCRYPT() and
DES_DECRYPT() from this file.
--enable-named-pipe
Enable support for named pipes. This option applies only on Windows NT, 2000, XP, and 2003 systems, and can be used only with the mysqld-nt and mysqld-max-nt servers that support named pipe connections.
--exit-info[=,
flags]-T [
flags]
This is a bit mask of different flags you can use for debugging the mysqld server. Do not use this option unless you know exactly what it does!
--external-locking
Enable system locking. Note that if you use this option on
a system on which lockd does not fully
work (as on Linux), it is easy for
mysqld to deadlock. This option
previously was named --enable-locking.
Note: If you use this
option to enable updates to MyISAM
tables from many MySQL processes, you have to ensure that
these conditions are satisfied:
You should not use the query cache for queries that use tables that are updated by another process.
You should not use
--delay-key-write=ALL or
DELAY_KEY_WRITE=1 on any shared
tables.
The easiest way to ensure this is to always use
--external-locking together with
--delay-key-write=OFF
--query-cache-size=0.
(This is not done by default because in many setups it's useful to have a mixture of the above options.)
--flush
Flush all changes to disk after each SQL statement. Normally MySQL does a write of all changes to disk only after each SQL statement and lets the operating system handle the synching to disk. See Section A.4.2, “What to Do If MySQL Keeps Crashing”.
--init-file=
file
Read SQL statements from this file at startup. Each statement must be on a single line and should not include comments.
--innodb-safe-binlog
Adds consistency guarantees between the content of
InnoDB tables and the binary log. See
Section 5.11.3, “The Binary Log”. This option was removed in
MySQL 5.0.3, having been made obsolete by the introduction
of XA transaction support.
--language=
lang_name,
-L lang_name
Client error messages in given language.
lang_name can be given as the
language name or as the full pathname to the directory
where the language files are installed. See
Section 5.10.2, “Setting the Error Message Language”.
--large-pages
Some hardware/operating system architectures support memory pages greater than the default (usually 4 KB). The actual implementation of this support depends on the underlying hardware and OS. Applications that perform a lot of memory access may obtain performance improvements by using large pages due to reduced Translation Lookaside Buffer (TLB) misses.
Currently, MySQL supports only the Linux implementation of large pages support (which is called HugeTLB in Linux). We have plans to extend this support to FreeBSD, Solaris and possibly other platforms.
Before large pages can be used on Linux, it is necessary
to configure the HugeTLB memory pool. For reference,
consult the hugetlbpage.txt file in
the Linux kernel source.
This option is disabled by default. It was added in MySQL 5.0.3.
--log[=,
file]-l [
file]
Log connections and queries to this file. See
Section 5.11.2, “The General Query Log”. If you don't specify a
filename, MySQL uses
as the filename.
host_name.log
--log-bin=[
file]
The binary log file. Log all queries that change data to
this file. Used for backup and replication. See
Section 5.11.3, “The Binary Log”. It is recommended to specify
a filename (see Section A.8.1, “Open Issues in MySQL” for the
reason) otherwise MySQL uses
as the log file basename.
host_name-bin
--log-bin-index[=
file]
The index file for binary log filenames. See
Section 5.11.3, “The Binary Log”. If you don't specify a
filename, and if you didn't specify one in
--log-bin, MySQL uses
as the filename.
host_name-bin.index
--log-bin-trust-function-creators[={0|1}]
With no argument or an argument of 1, this option sets the
log_bin_trust_function_creators system
variable to 1. With an argument of 0, this option sets the
system variable to 0.
log_bin_trust_function_creators affects
how MySQL enforces restrictions on stored function
creation. See Section 17.4, “Binary Logging of Stored Routines and Triggers”.
This option was added in MySQL 5.0.16.
--log-bin-trust-routine-creators[={0|1}]
This is the old name for
--log-bin-trust-function-creators. Before
MySQL 5.0.16, it also applies to stored procedures, not
just stored functions and sets the
log_bin_trust_routine_creators system
variable. As of 5.0.16, this option is deprecated. It is
recognized for backward compatibility but its use results
in a warning.
This option was added in MySQL 5.0.6.
--log-error[=
file]
Log errors and startup messages to this file. See
Section 5.11.1, “The Error Log”. If you don't specify a
filename, MySQL uses
as the filename. If the filename has no extension, an
extension of host_name.err.err is added to the
name.
--log-isam[=
file]
Log all MyISAM changes to this file
(used only when debugging MyISAM).
(DEPRECATED)
--log-long-format
Log extra information to whichever of the update log,
binary update log, and slow queries log that have been
activated. For example, username and timestamp are logged
for all queries. This option is deprecated, as it now
represents the default logging behavior. (See the
description for --log-short-format.) The
--log-queries-not-using-indexes option is
available for the purpose of logging queries that do not
use indexes to the slow query log.
--log-queries-not-using-indexes
If you are using this option with
--log-slow-queries, then queries that are
not using indexes also are logged to the slow query log.
See Section 5.11.4, “The Slow Query Log”.
--log-short-format
Log less information to whichever of the update log, binary update log, and slow queries log that have been activated. For example, the username and timestamp are not logged for queries.
--log-slow-admin-statements
Log slow administrative statements such as
OPTIMIZE TABLE, ANALYZE
TABLE, and ALTER TABLE to the
slow query log.
--log-slow-queries[=
file]
Log all queries that have taken more than
long_query_time seconds to execute to
this file. See Section 5.11.4, “The Slow Query Log”. See the
descriptions of the --log-long-format and