Installing MySQL on Unix

You'll need the following to install MySQL on a Unix machine:

  • An operating system in the Unix family (Linux, FreeBSD, and so on)

  • A copy of either the MySQL binaries or the MySQL source (if you want to compile MySQL yourself )

  • gunzip (gzip or zcat) and tar to extract and decompress the distribution file (the GNU versions are recommended)

  • Enough space on your system for MySQL

  • make and a C++ compiler (such as gcc) if you're planning to compile from source

Installing a Binary (tar) Distribution on Unix

To install MySQL on Unix from a binary distribution, perform the following steps:

  1. Change to the root user. You'll most likely need to be root to perform the commands that follow:

     % su - Password: 
  2. Add the MySQL user and MySQL group, which MySQL will run as. Never run MySQL as root! You can give the user and group another name if you want:

     % groupadd mysql % useradd -g mysql mysql 
    Note 

    The commands may be slightly different on your version of Unix ( for example, adduser and addgroup).

  3. Change to the directory you want to place MySQL in. By default, MySQL expects to be in /usr/local from a binary installation, but you can place this anywhere you like. If you change the location, you'll need to make some changes to the setup and to some of the utilities distributed with MySQL to point them to the new location:

     % cd /usr/local 
  4. Now extract the file:

     % gunzip -c /home/ mysql-max-4.x.x-platform-os-extra.tar.gz | tar -xf - 

The filename you'll see will depend on the distribution you're using. I'm seeing mysql-max-4.0.2-alpha-pc-linux-gnu-i686 at present. Make sure you have the right version for your system.

Warning 

The Sun version of tar has been known to give problems, so use the GNU version of tar instead.

Once this is complete, a new directory will have been created, based on the name of the distribution you're installing, as follows:

 % ls -l my* total 1 drwxr-xr-x  13 mysql   users        1024  Jul  1 14:15 mysql-max-4.x.x-platform-os-extra 

That name is a bit clunky for everyday use, and you'll most probably want to create a symlink mysql pointing to the new directory so that /usr/local/mysql/ can be the path to MySQL:

 % ln -s mysql-max-4.x.x-platform-os-extra mysql % ls -l my* lrwxrwxrwx   1 root     root           40  Jul 27 23:07 mysql -> mysql-max-4.x.x-platform-os-extra 

The newly installed directory contains the following:

 % cd mysql % ls -l total 4862 -rw-r--r--   1 mysql   users       19106 Jul  1 14:06 COPYING -rw-r--r--   1 mysql   users       28003 Jul  1 14:06 COPYING.LIB -rw-r--r--   1 mysql   users      122323 Jul  1 13:16 ChangeLog -rw-r--r--   1 mysql   users        6808 Jul  1 14:06 INSTALL-BINARY -rw-r--r--   1 mysql   users        1937 Jul  1 13:16 README drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 bin -rwxr-xr-x   1 mysql   users         773 Jul  1 14:15 configure drwxr-x---   4 mysql   users        1024 Jul  1 14:15 data drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 include drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 lib drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 man -rw-r--r--   1 mysql   users     2508431 Jul  1 14:06 manual.html -rw-r--r--   1 mysql   users     2159032 Jul  1 14:06 manual.txt -rw-r--r--   1 mysql   users       91601 Jul  1 14:06 manual_toc.html drwxr-xr-x   6 mysql   users        1024 Jul  1 14:15 mysql-test drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 scripts drwxr-xr-x   3 mysql   users        1024 Jul  1 14:15 share drwxr-xr-x   7 mysql   users        1024 Jul  1 14:15 sql-bench drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 support-files drwxr-xr-x   2 mysql   users        1024 Jul  1 14:15 tests

MySQL is now installed. To install the permission tables (see Chapter 14, "Database Security"), run the mysql_install_db script:

 % scripts/mysql_install_db Preparing db table Preparing host table Preparing user table Preparing func table Preparing tables_priv table Preparing columns_priv table Installing all prepared tables 020701 23:19:07  ./bin/mysqld: Shutdown Complete

Now, change the ownership to ensure that MySQL and the data directory are controlled by the newly created MySQL user, if they're not already:

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

After this, MySQL will be ready to roll with mysqld_safe:

 % /usr/local/mysql/bin/mysqld_safe --user=mysql & 
Tip 

Remember to assign a root password with mysqladmin as soon as you have finished installing; otherwise, MySQL will be wide open to anyone on the system. Also, you should immediately set about getting your configuration file right for your setup.

See Table 15.1 earlier in this chapter for an overview of the contents of the newly created directories.

Installing a Binary (rpm) Distribution on Unix

Red Hat Linux allows you to install MySQL from an RPM (Red Hat Package Manager) file as well.

Table 15.4 shows the full list of RPMs available. (The version numbers will reflect the version you are using.)

Table 15.4: Red Hat Package Manager Files

File

Description

MySQL-4.x.x-platform-os-extra.rpm

The MySQL server software, needed unless you're merely connecting to an existing server.

MySQL-client-4.x.x-platform-os-extra.rpm

The MySQL client software, needed to connect to a MySQL server.

MySQL-bench-4.x.x-platform-os-extra.rpm

Various MySQL tests and benchmarks. The Perl and msql-mysql rpm files are required.

MySQL-devel-4.x.x-platform-os-extra.rpm

Various libraries and include files required if you want to compile other MySQL clients.

MySQL-shared-4.x.x-platform-os-extra.rpm

The MySQL client shared libraries.

MySQL-embedded-4.x.x-platform-os-extra.rpm

The MySQL embedded server.

MySQL-4.x.x-platform-os-extra.src.rpm

The source code for the previous rpm files. Not required if you're doing a binary installation.

MySQL-Max-4.x.x-platform-os-extra

MySQL Max rpm (with support for InnoDB tables etc.).

To install the rpm files, simply run the rpm utility with each rpm you want to install listed. The client and server are typically the minimum you'll want to install:

 % rpm -i MySQL-4.x.x-platform-os-extra.rpm MySQL-client-4.x.x-platform-os-extra.rpm 

Installing via rpm results in a slightly different structure than that resulting from an ordinary binary installation. The data is placed in the /var/lib/mysql directory, and, by placing entries in the /etc/rc.d/ directory—as well as creating a /etc/rc.d/init.d/mysql script—MySQL is set up to begin automatically upon booting up. Be careful about installing over a previous installation in this way because you'll have to redo any changes you'd made.

After this, MySQL will be ready to roll with mysqld_safe:

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

Don't forget to assign a root password and look at your configuration file.

Installing from Source on Unix

You are unlikely to want to compile MySQL from source for production use unless you are experienced at these sorts of things. But some of you may enjoy the challenge, so this section explains the process in detail.

Tip 

It's important to look at the latest MySQL documentation because the following information can become dated quite quickly as new distributions replace older ones.

To install from a source distribution, you'll need the following:

  • gunzip (gzip or zcat). The GNU version is known to work.

  • tar (the GNU tar works, but the Solaris tar has caused problems in the past).

  • make (the GNU make is recommended, the Solaris and FreeBSD make have been known to cause problems).

  • gcc or pgcc (or another ANSI C++ compiler). Version 2.95.2 is recommended currently, although different distributions are usually compiled with different compilers. I suggest looking at the most recent MySQL documentation to see what they compile with for your operating system and whether there are any reported problems with other compilers.

To install from source, perform the following steps:

  1. To start with, as when installing binaries, change to be the root user and add the MySQL user and group:

     % su - Password:  % groupadd mysql % useradd -g mysql mysql 
  2. Move to the directory where you want to place the files (for example, /usr/local/src or wherever your convention dictates).

  3. Unpack the files:

    % gunzip -c /tmp/ mysql-4.x.x-platform-os-extra.tar.gz | tar -xf -

  4. Once complete, a new directory will have been created. Move into the new directory, which is where you're going to configure and build MySQL from:

     % cd mysql-4.x.x-extra 
  5. Run the configure script, which is a useful little script supplied with the distribution that allows you to set various options for you installation. There are a large number of options available. Some of the more useful ones are described next; others are mentioned in the "Compiling MySQL Optimally" sidebar later.

  6. By default, MySQL compiled from source will install into /usr/local, with the data and log files being stored in /usr/local/var. To change these locations, use the prefix option, for example:

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

    This changes the prefix of the entire installation to /usr/local/mysql instead. Alternatively, you can change the location of the data directory to /usr/local/mysql/data, while leaving the rest of the installation the same with the following:

     % ./configure --prefix=/usr/local \          --localstatedir=/usr/local/mysql/data 

    You can do one of the following instead if you prefer:

    • If you don't want to compile the server but just the client programs for connecting to an existing server, use the --without-server option:

       % ./configure --without-server 
    • To use libmysqld.a, the embedded MySQL library, you'll need to employ the --with-embedded-server option:

       % ./configure --with-embedded-server 
    • To change the location of the socket file from the default (usually /tmp), use configure as follows (the path name must be absolute):

       % ./configure --with-unix-socket-path=/usr/local/sockets/mysql.sock 

    • For a full set of available options, run the following:

       % ./configure --help 
  7. Once this is complete (which may take a little while depending on your setup), you'll need to build the binaries, with the make command:

     % make 
  8. Next, you'll need to install the binaries:

     % make install 
  9. Now, continue as you would have if you'd installed a binary, creating the permission tables and changing ownership of the files. These examples assume you decided on /usr/ local/mysql as prefix:

     % cd /usr/local/mysql % scripts/mysql_install_db Preparing db table Preparing host table Preparing user table Preparing func table Preparing tables_priv table Preparing columns_priv table Installing all prepared tables 010726 19:40:05  ./bin/mysqld: Shutdown Complete % chown -R root /usr/local/mysql % chgrp -R mysql /usr/local/mysql % chown -R mysql /usr/local/mysql/data  
  10. After this, MySQL will be ready to roll with mysqld_safe:

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

Don't forget to assign a root password and look at your configuration file.

start sidebar
Compiling MySQL Optimally

The standard MySQL distributions are fairly close to optimal compiles, but if you're out to get every last drop of performance, you can make some improvements. It's also quite easy to do the reverse and slow things down, so be careful when using the following tips:

  • You can define flags or the compiler name used by the compiler—for example:

     % CFLAGS=-O3 % CXX=gcc % CXXFLAGS=-O3 % CC=gcc % export CC CFLAGS CXX CXXFLAGS 
  • Link statically, not dynamically (in other words, use the --static option). This uses more disk space but runs faster (13 percent on Linux according to MySQL measurements).

  • MySQL binaries are mostly compiled with gcc because pgcc (Pentium gcc) has been known to cause problems on non-Intel processors. Compiling with pgcc if your processor is from the Intel Pentium family may result in some gains (1 percent according to MySQL tests, up to a reported 10-percent improvement). Similarly, on a Sun server, the SunPro C++ compiler has been about 5 percent faster than gcc in the past.

  • Optimize to the highest possible level (-O3 with gcc).

  • Compile without debug (the --without-debug option). This runs from between 20 and 35 percent faster than if you use the --with-debug=full option, and about 15 percent faster than if you use --with-debug.

  • MySQL distributions come with support for all character sets. Use the --with-extra-charsets=none option if you're just using the default ISO-8859-1 (Latin1) character set. Use the --with-charset=xxx option to compile just the character set(s) you plan to use.

  • If you're running Linux on x86 machines, compiling without frame pointers (-fomit-frame-pointer or -fomit-frame-pointer -ffixed-ebp) results in an improvement of between 1 and 4 percent.

end sidebar



Mastering MySQL 4
Mastering MySQL 4
ISBN: 0782141625
EAN: 2147483647
Year: 2003
Pages: 230
Authors: Ian Gilfillan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net