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

Option

Description

basedir = directory

Specifies the root directory of your MySQL install.

batch

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.

character-sets-dir= directory

Specifies where your character set files are stored.

compress

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

datadir= directory

Specifies the location of MySQL's data files.

debug= filename

Specifies a file to send debug information to.

force

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

host= hostname

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

language= language

Specifies the language to use for localization.

log= filename

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

log-isam= filename

Specifies the file to which isam changes should be logged.

password= password

Specifies a default password for clients to use to connect.

port= port_#

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

silent

Silently exit if a connection failure occurs.

skip-new-routines

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

skip-grant-tables

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

skip-locking

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

sleep= seconds

Sleep between commands.

socket= name

Socket file to use for local connections.

user= username

Specifies the user name to use for client connections.

variable-name = value

Sets the specified variable name to a particular value.

verbose

Tells MySQL to talk more about what is happening.

wait

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 [client] password        = my_password port            = 3306 socket          = /var/lib/mysql/mysql.sock     # These options are specifically targeted at the mysqld server [mysqld] port            = 3306 socket       = /var/lib/mysql/mysql.sock skip-locking 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.

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

 MYSQLSERVER=-YES- 
1.2.3.1.1 MySQL

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

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

The configuration file looks like this:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/ DTDs/PropertyList.dtd">     <plist version="0.9">   <dict>     <key>Description</key>     <string>MySQL Database Server</string>     <key>Provides</key>     <array>       <string>MySQL</string>     </array>     <key>Requires</key>     <array>       <string>Network</string>     </array>     <key>OrderPreference</key>     <string>Late</string>   </dict </plist> 

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

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

1.2.3.3 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   


MySQL
MySQL Pocket Reference: SQL Statements, Functions and Utilities and more (Pocket Reference (OReilly))
ISBN: 0596514263
EAN: 2147483647
Year: 2003
Pages: 13
Authors: George Reese

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net