The recommended way to install MySQL on Linux is by using an RPM file. The
MySQL RPMs are currently being built on a RedHat Version 6.2 system but should
work on other versions of Linux that support rpm and use glibc.
If you have problems with an RPM file, for example, if you receive the error
``Sorry, the host 'xxxx' could not be looked
up'', see section 2.6.1.1 Linux Notes
for Binary Distributions.
The RPM files you may want to use are:
MySQL-VERSION.i386.rpm The MySQL
server. You will need this unless you only want to connect to a MySQL server
running on another machine.
MySQL-client-VERSION.i386.rpm The
standard MySQL client programs. You probably always want to install this
package.
MySQL-bench-VERSION.i386.rpm Tests
and benchmarks. Requires Perl and msql-mysql-modules RPMs.
MySQL-devel-VERSION.i386.rpm
Libraries and include files needed if you want to compile other MySQL clients,
such as the Perl modules.
MySQL-VERSION.src.rpm This
contains the source code for all of the above packages. It can also be used to
try to build RPMs for other architectures (for example, Alpha or SPARC).
To see all files in an RPM package, run:
shell> rpm -qpl MySQL-VERSION.i386.rpm
To perform a standard minimal installation, run:
shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
To install just the client package, run:
shell> rpm -i MySQL-client-VERSION.i386.rpm
The RPM places data in `/var/lib/mysql'. The RPM also creates the appropriate entries in `/etc/rc.d/' to start the server automatically at boot time. (This means that if you have performed a previous installation, you may want to make a copy of your previously installed MySQL startup file if you made any changes to it, so you don't lose your changes.)
After installing the RPM file(s), the mysqld daemon should be running and you should now
be able to start using MySQL. See section 2.4 Post-installation
Setup and Testing.
You need the following tools to install a MySQL binary distribution:
gunzip to uncompress the
distribution.
tar to unpack the
distribution. GNU tar is known to
work. Sun tar is known to have
problems. An alternative installation method under Linux is to use RPM (RedHat Package Manager) distributions. See section 2.1.1 Installing MySQL on Linux.
If you run into problems, PLEASE ALWAYS USE mysqlbug when posting questions to mysql@lists.mysql.com. Even if the
problem isn't a bug, mysqlbug gathers
system information that will help others solve your problem. By not using
mysqlbug, you lessen the likelihood of
getting a solution to your problem! You will find mysqlbug in the `bin' directory after you unpack the distribution. See
section 1.2.22.3 How to
Report Bugs or Problems.
The basic commands you must execute to install and use a MySQL binary distribution are:
shell> groupadd mysql shell> useradd -g mysql mysql shell> cd /usr/local shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s mysql-VERSION-OS mysql shell> cd mysql shell> scripts/mysql_install_db shell> chown -R root /usr/local/mysql shell> chown -R mysql /usr/local/mysql/data shell> chgrp -R mysql /usr/local/mysql shell> chown -R root /usr/local/mysql/bin shell> bin/safe_mysqld --user=mysql &
You can add new users using the bin/mysql_setpermission script if you install the
DBI and Msql-Mysql-modules Perl modules.
A more detailed description follows.
To install a binary distribution, follow the steps below, then proceed to section 2.4 Post-installation Setup and Testing, for post-installation setup and testing:
root.)
tar archives and have names like `mysql-VERSION-OS.tar.gz', where VERSION is a number (for example, 3.21.15), and OS indicates the type of operating system for
which the distribution is intended (for example, pc-linux-gnu-i586).
-max prefix, this means that the binary has
support for transaction-safe tables and other features. See section 4.7.5 mysqld-max, An
extended mysqld server. Note that all binaries are built from the same
MySQL source distribution.
mysqld to
run as: shell> groupadd mysql shell> useradd -g mysql mysqlThese commands add the
mysql
group and the mysql user. The syntax
for useradd and groupadd may differ slightly on different versions
of Unix. They may also be called adduser and addgroup. You may wish to call the user and group
something else instead of mysql.
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s mysql-VERSION-OS mysqlThe first command creates a directory named `mysql-VERSION-OS'. The second command makes a symbolic link to that directory. This lets you refer more easily to the installation directory as `/usr/local/mysql'.
shell> cd mysqlYou will find several files and subdirectories in the
mysql directory. The most important for
installation purposes are the `bin' and
`scripts' subdirectories.
PATH environment variable so
that your shell finds the MySQL programs properly. See section H Environment
Variables.
mysql_install_db script used to initialize the
mysql database containing the grant
tables that store the server access permissions. mysqlaccess and have the MySQL distribution in
some non-standard place, you must change the location where mysqlaccess expects to find the mysql client. Edit the `bin/mysqlaccess' script at approximately line 18.
Search for a line that looks like this: $MYSQL = '/usr/local/bin/mysql'; # path to mysql executableChange the path to reflect the location where
mysql actually is stored on your system. If you do
not do this, you will get a Broken
pipe error when you run mysqlaccess.
shell> scripts/mysql_install_dbNote that MySQL versions older than Version 3.22.10 started the MySQL server when you run
mysql_install_db.
This is no longer true!
root and ownership of the data directory to the
user that you will run mysqld as: shell> chown -R root /usr/local/mysql shell> chown -R mysql /usr/local/mysql/data shell> chgrp -R mysql /usr/local/mysqlThe first command changes the
owner attribute of the files to the root user, the second one changes the owner attribute of the data directory to the
mysql user, and the third one changes
the group attribute to the mysql group.
DBI/DBD
interface, see section M.2 Perl Installation
Comments.
support-files/mysql.server to the location where
your system has its startup files. More information can be found in the
support-files/mysql.server script
itself and in section 2.4.3 Starting and
Stopping MySQL Automatically. After everything has been unpacked and installed, you should initialize and test your distribution.
You can start the MySQL server with the following command:
shell> bin/safe_mysqld --user=mysql &
See section 4.7.2 safe_mysqld, the wrapper around mysqld.
See section 2.4 Post-installation Setup and Testing.
Once you've installed MySQL (from either a binary or source distribution), you need to initialize the grant tables, start the server, and make sure that the server works okay. You may also wish to arrange for the server to be started and stopped automatically when your system starts up and shuts down.
Normally you install the grant tables and start the server like this for installation from a source distribution:
shell> ./scripts/mysql_install_db shell> cd mysql_installation_directory shell> ./bin/safe_mysqld --user=mysql &
For a binary distribution (not RPM or pkg packages), do this:
shell> cd mysql_installation_directory shell> ./bin/mysql_install_db shell> ./bin/safe_mysqld --user=mysql &
This creates the mysql database which
will hold all database privileges, the test database which you can use to test MySQL and
also privilege entries for the user that run mysql_install_db and a root user (without any passwords). This also starts
the mysqld server.
The mysql.server and safe_mysqld scripts can be used to start the server
automatically at system startup time. mysql.server can also be used to stop the server.
The mysql.server script can be used
to start or stop the server by invoking it with start or stop arguments:
shell> mysql.server start shell> mysql.server stop
mysql.server can be found in the
`share/mysql' directory under the MySQL
installation directory or in the `support-files' directory of the MySQL source tree.
Before mysql.server starts the
server, it changes directory to the MySQL installation directory, then invokes
safe_mysqld. You might need to edit
mysql.server if you have a binary
distribution that you've installed in a non-standard location. Modify it to
cd into the proper directory before it
runs safe_mysqld. If you want the server
to run as some specific user, add an appropriate user line to the `/etc/my.cnf' file