1.2 Installation

You can install MySQL by compiling the source code with the options that best suit your needs, or by downloading and installing a prebuilt binary. In general, you'll want to use the package management system (such as the BSD ports system) appropriate to your operating system. You can also find both binary and source code at the MySQL web site, http://www.mysql.com.

Before installing using either approach, you need to prepare your operating system for MySQL. Specifically, you should create a mysql user and group under which MySQL will run.

1.2.1 Compilation

Compiling MySQL requires the following steps:

  1. Run configure

    Configure comes with a host of options you can specify using the syntax configure --option[=value]. For example, configure --prefix=/usr/local/mysql tells the installer to use /usr/local/mysql as its installation directory.

  2. Run make

    This step performs the actual compilation.

  3. Run makeinstall

    This step takes the compiled binaries and installs all components of MySQL in their proper locations.

  4. Under Unix, make sure directory owners are all in order.

    chown -R root {INSTALL_DIR}
    chgrp -R mysql {INSTALL_DIR}
    chown -R mysql {DATA_DIR}

1.2.2 Configuration

MySQL has three different kinds of configuration, both for the server process at server startup and for the client processes when a user executes them. In order of preference, these configuration options include:

  1. Command-line options

  2. Configuration file options

  3. Environment variable options

In other words, if you have the password option specified on the command line, in your configuration file, and in an environment variable, the command-line option wins. Table 1-1 shows a list of configuration options. Each option applies to one or more MySQL tools, depending on the context.

Table 1-1. MySQL configuration options




Specifies the root directory of your MySQL install.


Executes in batch mode, meaning no command-line prompts or other information is sent to stdout. This is the default mode when used with a pipe.


Specifies where your character set files are stored.


Tells the client and server to use compression in the network protocol.


Specifies the location of MySQL's data files.


Specifies a file to send debug information to.


Indicates that you want processing to continue for client utilities even when an error is encountered.


Identifies the host to which a client should connect by default.


Specifies the language to use for localization.


Specifies the file to which connections and queries should be logged.


Specifies the file to which isam changes should be logged.


Specifies a default password for clients to use to connect.


Specifies the port number to which the server should listen and to which clients should connect.


Silently exit if a connection failure occurs.


Tells the MySQL server to avoid new, potential buggy routines.


Tells the server to ignore all grant tables, effectively giving all users full access to the database server.


Potentially provides better system performance by avoiding system locking. It should not be used in conjunction with isamchk or myisamchk.


Sleep between commands.


Socket file to use for local connections.


Specifies the user name to use for client connections.

variable-name =value

Sets the specified variable name to a particular value.


Tells MySQL to talk more about what is happening.


Tells the client to wait after a connection failure and then retry the connection.

A MySQL configuration file has the following format:

# Example MySQL configuration file
# These options go to all clients
password        = my_password
port            = 3306
socket          = /var/lib/mysql/mysql.sock
# These options are specifically targeted at the mysqld server
port            = 3306
socket       = /var/lib/mysql/mysql.sock
set-variable = max_allowed_packet=1M

MySQL supports multiple configuration files. As a general rule, it checks files in the following order of preference:

  1. User configuration file (Unix only).

  2. Configuration file specified through the --defaults-extra-file=filename option.

  3. A configuration file in the MySQL data directory.

  4. The system configuration file.

In all cases except the command-line and user configuration options, the name of the configuration file on Unix is my.cnf and on Windows is my.ini. A Unix user can override system configuration information by building their own configuration file in ~/.my.cnf. The system configuration file on a Unix system is /etc/my.cnf. Windows, on the other hand, has two system configuration locations, in order of preference:

  1. C:\my.cnf

  2. C:\WINNT\System32\my.cnf

You can alternately specify a file on the command line using the --defaults-file=filename option. This option causes all options specified in other files to be ignored, even if they are not overridden in the file you specify.

1.2.3 Startup

In general, you will want MySQL to begin running when the operating system comes up. How you do this depends on your operating system. Mac OS X

Mac OS X automatically executes all scripts under the /Library/StartupItems directory when the system boots up. If that directory does not yet exist, you will need to create it. For MySQL, you should create the directory /Library/StartupItems/MySQL and place the startup shell script MySQL and the configuration file StartupParameters.plist in that directory.

Once those files are set up, you need to edit the host configuration file /etc/hostconfig and add the line:


The shell script to start, stop, and restart MySQL looks like this:

. /etc/rc.common
StartService(  )
    if [ "${MYSQLSERVER:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting MySQL"
        cd /usr/local/mysql
        bin/mysqld_safe --user=mysql &
StopService(  )
    ConsoleMessage "Stopping MySQL"
    /usr/local/mysql/bin/mysqladmin shutdown
RestartService(  )
    if [ "${MYSQLSERVER:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Restarting MySQL"
RunService "$1" StartupParameters.plist

The configuration file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/
<plist version="0.9">
    <string>MySQL Database Server</string>

Once installed, you should run the mysql_install_db tool to set up your databases. Other Unix

Setting up other variants of Unix is as simple as copying the script mysql.server from the source's support-files directory to your version of Unix's startup directory and making sure it is executable by root. Under FreeBSD, for example, place this script in /usr/local/etc/rc.d.

Once installed, you should run the mysql_install_db tool to set up your databases. Windows 2000/XP

To startup an application at system startup on the Windows platform, you need to install it as a Windows service. You can do this by hand using the command:

C:\> c:\mysql\bin\mysqld-nt --install

A more convenient way to do accomplish this task is through the winmysqladmin.exe utility that comes with the Windows installation of MySQL.

1.2.4 Set the Root Password

After starting the server, and before doing anything else, set a password for the root user:

mysqladmin -u root password a_good_password