3.3. Installing MySQL

Although MySQL runs on many platforms, we describe how to install it on Linux, Unix, Windows, and Mac, which together account for the majority of Web sites on the Internet. Be sure to read the instructions all the way through before beginning the installation.

3.3.1. Installing MySQL on Windows

MySQL for Windows includes two wizards:

  • Setup Wizard: The Setup Wizard installs MySQL. The directories are created and the files are copied into the appropriate locations.

  • Configuration Wizard: The Configuration Wizard installs MySQL as a service, creates the MySQL accounts and passwords required to access the database, and configures other MySQL settings.

When you install MySQL for the first time, you need to run the Configuration Wizard after you run the Setup Wizard. You can't access the MySQL databases until you run the Configuration Wizard.

3.3.1.1. Running the MySQL Setup Wizard

To set up MySQL on Windows, follow these steps:

  1. Double-click the installer (.msi) file that you downloaded.

    The file is named mysql-essential-, followed by the version number, followed by -win32.msi, such as mysql-essential-5.0.37-win32.msi.

    The opening screen shown in Figure 3-1 is displayed. Note: If you're installing from a Windows NT/2000/XP/Vista system, be sure that you're logged into an account with administrative privileges.

    In Vista, you might need to right-click the filename and choose Run as Administrator.

    Figure 3-1. The opening screen of the MySQL Setup Wizard.
  2. Click Next.

    You see a screen for choosing the type of installation.

  3. Select Typical and then click Next.

    The Ready to Install Program screen opens. The current settings are displayed.

  4. Click Install.

    The installation of MySQL begins. When the installation is complete, a Sign-Up screen opens.

  5. Click Skip Signup and then click Next.

    The Wizard Completed screen appears, as shown in Figure 3-2.

    Figure 3-2. The Wizard Completed screen of the MySQL Setup Wizard.
  6. If you're installing this version of the server for the first time, select the Configure the MySQL Server Now check box.

    If you're upgrading the MySQL server, such as from MySQL 5.0.18 to 5.0.22, you might not need to configure the server. The wizard will give it the same configuration as the existing version. However, if you're upgrading to a new major version, such as from MySQL 5.0 to MySQL 5.1, you need to run the Configuration Wizard.

  7. Click Finish.

If you selected the Configure the MySQL Server Now check box, the Configuration Wizard starts immediately. Running the MySQL Configuration Wizard is explained in the next section. If you didn't select it, the Setup Wizard stops running.

3.3.1.2. Running the MySQL Configuration Wizard

After you install MySQL, you must configure it. You need to assign a password to the MySQL account, named root, which is installed automatically. You need to start the server and set it up so that it automatically starts when your computer boots.

MySQL provides a Configuration Wizard. The Configuration Wizard starts immediately after installation if you selected the Configure the MySQL Server Now check box in the final setup screen. You can also start the Configuration Wizard at any time with a menu item in the MySQL Start Menu.

  1. Choose StartAll ProgramsMySQLMySQL Server 5.0MySQL Server Instance Config Wizard.

    The Configuration Wizard starts, as shown in Figure 3-3.

    Figure 3-3. The first screen in the MySQL Configuration Wizard.
  2. If you have more than one version of MySQL installed, a screen appears, and you can click the version you want to configure. Then click Next.

    The MySQL Server Configuration Types screen opens.

  3. Click Standard Configuration and then click Next.

    The Windows Options screen opens.

  4. Select the Install as a Windows Service option.

    If you're using Windows 98/Me, installing as a Windows service isn't possible. Instead, select the Add Bin Directory to Windows PATH option and skip to Step 7.

  5. In the Service Name text box, type mysql50.

  6. Select the Launch the MySQL Server Automatically option.

  7. Click Next.

    The Security Options screen opens, as shown in Figure 3-4.

    Figure 3-4. The Security Options screen in the MySQL Configuration Wizard.
  8. Select the Modify Security Settings check box.

  9. In the New Root Password text box, type a password. In the Confirm text box, retype the same password.

    If MySQL was configured previously, this screen asks for the current password.

    NOTE

    You're now setting the password for the root account for your MySQL server. You must use the root account to access your MySQL database. You need to remember the password you type here.

  10. If you're setting up a development environment that no one can access but you, you can select the Create an Anonymous Account check box.

    An anonymous account is handy. However, if there is any access to your MySQL server from the Internet, don't create an anonymous account. It's a security risk.

  11. Click Next.

    The Ready to Execute screen opens.

  12. Click Execute.

    A message appears when the configuration is complete.

3.3.2. Installing MySQL on Linux from an RPM file

MySQL can be installed on Linux using RPM. Although RPM stands for Red Hat Package Manager, RPM is available on most flavors of Linux, not just Red Hat.

To install MySQL on Linux from an RPM file provided on the MySQL Web site, follow these steps:

  1. Change to the directory where you saved the downloaded files.

    For instance, type cd /usr/src/mysql.

    One file is named MySQL-server-, followed by the version number, followed by .i386.rpm. The second file has the same name with client, instead of server in the name.

  2. Install the RPM by entering this command:

    rpm -i listofpackages

    For instance, the command might be

    rpm -i MySQL-server-5.0.35-0.i386.rpm MySQL-client-5.0.35-0.i386.rpm

    This command installs the MySQL packages. It sets the MySQL account and group name that you need and creates the data directory at /var/lib/mysql. It also starts the MySQL server and creates the appropriate entries in /etc/rc.d so that MySQL starts automatically whenever your computer starts.

    You need to be using an account that has permissions to successfully run the rpm command, such as a root account.

  3. To test that MySQL is running okay, type this:

    bin/mysqladmin --version

    You should see the version number of your MySQL server.

3.3.3. Installing MySQL on Mac from a PKG file

You can install MySQL using a Mac OS X 10.2 (Jaguar) or later PKG binary package downloaded from the MySQL Web site at www.mysql.com. If your operating system is earlier than OS X 10.2, you can't use this package; you will need to download a tarball (a file that is a container for many files and subdirectories) and install MySQL from source code, as described in the next section.

  1. Create a user and a group named mysql for MySQL to run under.

    In most newer Mac versions of OS X, this user and group already exist.

  2. Change to the directory where you downloaded MySQL — for instance, /usr/local.

    You see a package named mysql-, followed by the version number and the OS number and dmg, such as mysql- 5.0.37-osx10.4-powerpc.dmg. If the downloaded file doesn't have the extension .dmg, change the filename to give it the .dmg extension.

  3. Mount the disk image by double-clicking its icon in the Finder.

  4. Double-click the package icon to install the MySQL PKG.

    The package installer runs and installs the package. It installs MySQL in the directory /usr/local/mysql-, followed by the version number. It also installs a symbolic link, /usr/local/mysql/, pointing to the directory where MySQL is installed. It initializes the database by running the script mysql_install_db, which creates a MySQL account called root.

  5. If necessary, change the owner of the mysql directory.

    The directory where MySQL is installed (for example, /usr/local/mysql-5.0.37) should be owned by root. The data directory (such as /usr/local/mysql-5.0.37/data) should be owned by the account mysql. Both directories should belong to the group mysql. If the user and group aren't correct, change them with the following commands:

    sudo chown -R root /usr/local/mysql-5.0.37
    sudo chown -R mysql /usr/local/mysql-5.0.37/data
    sudo chown -R root /usr/local/mysql-5.0.37/bin

  6. Install the MySQL Startup Item.

    To have your server start every time the computer starts, you need to install the MySQL Startup Item, which is included in the installation disk image in a separate installation package. To install the Startup Item, double-click the MySQLStartupItem.pkg icon.

3.3.4. Installing MySQL from source files

Before you decide to install MySQL from source files, check for RPMs or binary files for your operating system. MySQL RPMs and binary files are precompiled, ready-to-install packages for installing MySQL and are convenient and reliable.

You can install MySQL by compiling the source files and installing the compiled programs. This process sounds technical and daunting, but it's not. However, read all the way through the following steps before you begin the installation procedure.

To install MySQL from source code, follow these steps:

  1. Create a user and group ID for MySQL to run under by using the following commands:

    groupadd mysql
    useradd -g mysql mysql

    The syntax for the commands might differ slightly on different versions of Unix, or they might be called addgroup and adduser.

    Note: You must be using an account authorized to add users and groups.

    Note: Some recent Linux distributions and Macs have a mysql account already created.

  2. Change to the directory where you downloaded the source tarball — for instance, cd-/usr/local.

    You see a file named mysql-, followed by the version number and .tar.gz. — for instance, mysql-5.0.35.tar.gz. This file is a tarball.

  3. Unpack the tarball by typing

    gunzip -c filename | tar -xvf -

    For example:

    gunzip -c mysql-5.0.35.tar.gz | tar -xvf -

    You see a new directory named mysql-version — for instance, mysql-5.0.35 — which contains many files and subdirectories. You must be using an account that is allowed to create files in /usr/local.

  4. Change to the new directory.

    For instance, you might type cd mysql-5.0.35.

  5. Type the following:

    ./configure --prefix=/usr/local/mysql

    You see several lines of output. The output will tell you when configure has finished. This might take some time.

  6. Type make.

    You see many lines of output. The output will tell you when make has finished. make might run for some time.

  7. Type make install.

    On a Mac, type sudo make install.

    make install finishes quickly.

    Note: You might need to run this command as root.

  8. Type scripts/mysql_install_db.

    This command runs a script that initializes your MySQL databases.

  9. Make sure that the ownership and group membership of your MySQL directories are correct. Set the ownership with these commands:

    chown -R root  /usr/local/mysql
    chown -R mysql /usr/local/mysql/data
    chgrp -R mysql /usr/local/mysql

    These commands make root the owner of all the MySQL directories except data and make mysql the owner of data. All MySQL directories belong to group mysql.

  10. Start the MySQL server using the following commands:

    On a Mac:

    cd /usr/local/mysql
    sudo ./bin/mysqld_safe

    If necessary, enter your password. Press Ctrl+Z, and then type:

    bg

    Finally, press Ctrl+D or type exit.

    On Linux/Unix:

    cd /usr/local/mysql
    bin/mysqld_safe --user=mysql &

  11. Set up your computer so that MySQL starts automatically when your machine starts by copying the file mysql.server from /usr/local/mysql/support-files to the location where your system has its startup files.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.127.68