1.2 InstallationYou 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 CompilationCompiling MySQL requires the following steps: Run configureConfigure 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. Run makeThis step performs the actual compilation. Run makeinstallThis step takes the compiled binaries and installs all components of MySQL in their proper locations. Under Unix, make sure directory owners are all in order. chown -R root {INSTALL_DIR} 1.2.2 ConfigurationMySQL 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: Command-line options Configuration file options 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.
# Example MySQL configuration file MySQL supports multiple configuration files. As a general rule, it checks files in the following order of preference: User configuration file (Unix only). Configuration file specified through the --defaults-extra-file=filename option. A configuration file in the MySQL data directory. 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: C:\my.cnf 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 StartupIn 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 XMac 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 MySQLThe shell script to start, stop, and restart MySQL looks like this: #!/bin/sh 1.2.3.1.2 StartupParameters.plistThe configuration file looks like this: <?xml version="1.0" encoding="UTF-8"?> Once installed, you should run the mysql_install_db tool to set up your databases. 1.2.3.2 Other UnixSetting 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/XPTo 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 PasswordAfter starting the server, and before doing anything else, set a password for the root user: mysqladmin -u root password a_good_password |