[ Team LiB ] |
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:
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:
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.
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:
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:
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 . /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" 1.2.3.1.2 StartupParameters.plistThe 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 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 |
[ Team LiB ] |