-
Download the latest version of MySQL from
http://www.mysql.com/downloads/mysql.html
. 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. -
Uncompress the package in the new installation directory by running:
% gzip -d mysql-<
version
>.tar.gzIf MySQL 3.23.42 has been downloaded, the command is:
% gzip -d mysql-3.23.42.tar.gz
-
Un-tar the tape archive file by running:
% tar xvf mysql-<
version_number
>.tarA 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
-
Change directory to the MySQL distribution directory:
% cd mysql-<
version
>If the version is MySQL 3.23.42, type:
% cd mysql-3.23.42
-
Add a new Unix group account for the MySQL files:
% groupadd mysql
-
Add a new Unix user who is a member of the newly created Unix group
mysql
:% useradd -g mysql mysql
-
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.
-
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
-
Compile the MySQL DBMS:
% make
-
Install MySQL in the location chosen in Step 7 by running the command:
% make install
-
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
-
Change the owner of the MySQL program files to be the
root
user:% chown -R root /usr/local/mysql
-
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
-
Change the group of the MySQL installation files to be the
mysql
group:% chgrp -R mysql /usr/local/mysql
-
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
-
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 [mysqld]
In this section, add the following line, then save the file, and exit the editor:
set-variable = max_connections=150
-
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 &
-
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
-
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.
-
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.