Installing MySQL

The instructions here are for installing MySQL 3. MySQL is bundled with only some Linux installations. We assume that MySQL isn't installed or, if it is installed, that a new version is to be installed to replace the current installation.

  1. Download the latest version of MySQL from Choose the latest stable release and, from the stable release page, choose the option under "Source Downloads" marked "tarball (.tar.gz)". Download the file into a directory where files can be created and there is sufficient disk space. A good location is /tmp. Change directory to this location using:

    % cd /tmp

    Note that the % character should not be typed in; this represents the Linux shell prompt and indicates that the command should be entered at the shell prompt.

  2. Uncompress the package in the new installation directory by running:

    % gzip -d mysql-<version>.tar.gz

    If MySQL 3.23.42 has been downloaded, the command is:

    % gzip -d mysql-3.23.42.tar.gz
  3. Un-tar the tape archive file by running:

    % tar xvf mysql-<version_number>.tar

    A list of files that are extracted is shown.

    If the version downloaded is MySQL 3.23.42, the command is:

    % tar xvf mysql-3.23.42.tar
  4. Change directory to the MySQL distribution directory:

    % cd mysql-<version>

    If the version is MySQL 3.23.42, type:

    % cd mysql-3.23.42
  5. Add a new Unix group account for the MySQL files:

    % groupadd mysql
  6. Add a new Unix user who is a member of the newly created Unix group mysql:

    % useradd -g mysql mysql
  7. Decide on an installation directory. Later, we recommend that PHP and Apache be installed in /usr/local/, so a good choice is /usr/local/mysql/. We assume throughout these steps that /usr/local/mysql/ is used; if another directory is chosen, replace /usr/local/mysql/ with the alternative choice in the remaining steps.

  8. Configure the MySQL installation by running the configure script. This detects the available Linux tools and the installation environment for the MySQL configuration:

    % ./configure --prefix=/usr/local/mysql
  9. Compile the MySQL DBMS:

    % make
  10. Install MySQL in the location chosen in Step 7 by running the command:

    % make install
  11. MySQL is now installed but isn't yet configured. Now, run the mysql_install_db script to initialize the system databases used by MySQL:

    % ./scripts/mysql_install_db
  12. Change the owner of the MySQL program files to be the root user:

    % chown -R root /usr/local/mysql
  13. Change the owner of the MySQL databases and log files to be the mysql user created in Step 6:

    % chown -R mysql /usr/local/mysql/var
  14. Change the group of the MySQL installation files to be the mysql group:

    % chgrp -R mysql /usr/local/mysql
  15. Copy the default medium-scale parameter configuration file to the default location of /etc. These parameters are read when MySQL is started. The copy command is:

    % cp support-files/my-medium.cnf /etc/my.cnf
  16. Edit the configuration file and adjust the default number of maximum connections to match the default value for the maximum Apache web server connections. Using a text editor, edit the file /etc/my.cnf, and find the section beginning with the following text:

    # The MySQL server

    In this section, add the following line, then save the file, and exit the editor:

    set-variable    = max_connections=150
  17. The MySQL configuration is now complete, and MySQL is ready to be started. Start the MySQL DBMS with the following command:

    % /usr/local/mysql/bin/safe_mysqld --user=mysql &
  18. Check that the MySQL DBMS is running with the mysqladmin utility. The following command reports statistics about the MySQL DBMS version and usage:

    % /usr/local/mysql/bin/mysqladmin version
  19. Choose and set a password for root user access to the MySQL DBMS. To set a password of secret, use:

    % /usr/local/mysql/bin/mysqladmin -uroot password secret

    Record the password for later use.

  20. The MySQL server is currently running. However, when the machine is rebooted, MySQL doesn't restart automatically.

    After reboot, the command in Step 17 can be used to restart MySQL or, alternatively, this process can be made automatic. To make the process automatic, find the file rc.local (normally either in or below the directory /etc). This file is used to list locally installed software that should be run on startup. Using an editor, add the following line to the bottom of the rc.local file:

    /usr/local/mysql/bin/safe_mysqld --user=mysql &

The installation of MySQL is now complete.

These steps install MySQL and start the DBMS server but don't configure a user or user databases. The steps to add a user are the subject of the next section.