Installing MySQL-Max

There are several different methods of obtaining MySQL:

  • Install a binary package, either using some sort of formal package or just a tar file.
  • Compile from source, using a package of source code.
  • Download the latest nightly build and compile from that, using BitKeeper.

The easiest method is to install a binary package with precompiled executables and libraries and that does not require any configuration to work. All the files will be placed in whatever the maker of the package considers the "standard" location. The binaries can come in RPM or other package such as a Mac OS X package (either directly from MySQL.com or from your Linux/UNIX distributor, such as Red Hat) or as a tarball that you can download from MySQL.com. There is a significant distinction between these two methods: The tarball puts all the files in one folder (if you follow the guide in the manual, it is /usr/local/mysql). The RPM package, however, does not put all the files in one folder, but spreads them out according to where you get the binary from. This can lead to confusion, so if you install binaries from someone other than MySQL.com, you should make sure to spend some time familiarizing yourself with any different locations for files.

Note

You should ensure that you get the MySQL-Max release and not the regular distribution. The -Max designation means that the compilation has extra features compared to the regular distribution. One such feature is enabling support for MySQL Cluster, which you definitely need if you want to set up such a cluster!

The second, and far less common and more complex, method of installing MySQL-Max is to compile from source. There are many valid reasons to do this, but for the sake of performance and sanity, we recommend that you do not compile from source if possible but instead use a precompiled binary package. Furthermore, we suggest that if possible, you use a binary package provided by MySQL rather than your Linux distributor. If you ever want supporteither paid-for support from MySQL or just helpful people on the mailing listsyou will find it much easier to get help if you have all your files in the place that MySQL decided to put them rather than wherever your distribution provider decided to put them. For example, in this book we assume that my.cnf is in the /etc/ folder. On Debian binary installations, it is actually in /etc/mysql/, which may well cause confusion, particularly for users fairly new to Linux or a particular distribution. Another reason to avoid third-party binaries is that most of their distributions do not include support for MySQL Cluster. A final reason to use the packages provided by MySQL is that you know that you can always access the latest version; you also do not rely on someone else to produce a package, which may take time.

Although we recommend that you install MySQL using the binary tarball available from MySQL.com, this chapter briefly covers installing MySQL using all common methods. In this book, we use CentOS 4.0, which is identical (except for branding) to Red Hat Enterprise Linux 4 and is a good choice if you want a solid Linux distribution without any formal support; however, you should find that these steps work correctly on all common Linux distributions.

This chapter also covers installing the latest nightly release from BitKeeper. You should not do this unless you hit a bug that is not fixed in a regular release but that has been fixed by a developer and will be in the nightly build. (BitKeeper is really just the "cutting edge" source code and includes lots of code that is new or has changed since the last formal release.) We include this information here simply because there are few clear guides available on this topic, yet installing BitKeeper is not particularly difficult to do. We strongly recommend that you never use code from BitKeeper in a production environment because it has not been tested as much (or at all, in some cases) as a full release.

Note that if you are running SELinux (Security Enhanced Linux), you should either create a new policy or disable it. Creating policies is beyond the scope of this book, but basically, to disable it, you edit the file /etc/sysconfig/selinux, change/add the SELINUX=disabled line, and reboot the system. If you want to leave SELinux enabled, visit the website for this book to download a rule that will allow you to run a MySQL cluster with SELinux.

All the examples in this book are for MySQL Cluster version 5.0, which we expect will be the generally available release by the time that this book is published. However, the steps are virtually identical for versions 4.1 and 5.1.

Installing MySQL Cluster from a Binary Tarball

To install MySQL Cluster from a binary tarball, you need to locate the correct tarball for your platform at the MySQL download page (for version 5.0, this is http://dev.mysql.com/downloads/mysql/5.0.html) and then obtain the relevant file. You then need to extract it, move it to the correct folder, add the mysql user, set up the initial tables, and start the server:

[user@host] su -
[root@host] cd /usr/local/
[root@host] wget /mysql-max-5.0.11-beta-linux-i686.tar.gz
[root@host] tar -zxvf mysql-max-5.0.11-beta-linux-i686.tar.gz
[root@host] rm -f mysql-max-5.0.11-beta-linux-i686.tar.gz
[root@host] ls
bin games lib mysql-max-5.0.12-beta-linux-i686 share
etc include libexec sbin src

Note that a folder is created, with the "full" name of the distribution (mysql-max-5.0.12-beta-linux-i686, in the preceding example). For the sake of neatness and upgradeability, you should create a soft link (that is, a symlink) to this folder mysql. This also helps with upgrading because you can install both the older and new versions and then just stop MySQL, change the link, and start the upgraded version very easily. You can create this link easily:

[root@host] ln -s mysql-max-5.0.11-beta-linux-i686 mysql
[root@host] cd mysql

The MySQL database server can run as either root or any other user on the system. From a security point of view, it's a bad idea (and the developers have made it quite difficult) to run the MySQL database server as root; therefore, you should create a special mysql user and group for this purpose:

[root@host] groupadd mysql
[root@host] useradd -g mysql mysql

Now you need to tell MySQL where you want it to store its data. Unless you want it to store the databases in the same folder as the actual programs (/usr/local/mysql/data/), you should create a file called /etc/my.cnf that has the following contents:

Note

Storing the databases in the same folder as the actual programs is probably a bad idea. It is almost always a good idea to keep your data (databases) far away from your applications (binaries). This makes upgrading much easier, and it reduces the chance of a botched upgrade or installation destroying your data. If you choose not to follow this advice, you should change the second chown command to change the permissions on the folder /usr/local/mysql/data.

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Next, you need to initialize the system database and tables. This means creating the mysql and test databases as well as the system tables that MySQL needs in order to run. You must also make sure that these new tables are owned by the mysql user:

[root@host] mkdir /var/lib/mysql
[root@host] /usr/local/mysql/scripts/mysql_install_db
[root@host] chown -R root:mysql /usr/local/mysql
[root@host] chown -R mysql:mysql /var/lib/mysql

On distributions of Linux that support the service servicename start command and syntax, you should copy the helpful mysql.server script into the /etc/rc.d/init.d/ folder (where the service command can find it):

[root@host] cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
[root@host] service mysql start

Otherwise, you should copy the mysql server to wherever your distribution keeps init scripts and execute it.

You now need to add the MySQL bin directory to the PATH variable so you do not need to append /usr/local/mysql/bin/ before each binary name every time you want to use it. If you use the BASH shell, as most distributions do, you need to edit your .bash_profile file in your home directory. You need to make sure to change this file for each user on the system. Essentially, this involves opening up $HOME/.bash_profile with a text editor (such as vi/vim, pico, or emacs) and adding /usr/local/mysql/bin to the line that defines the variable $PATH, which may look something like this:

PATH=$PATH:$HOME/bin

You change it to this:

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

Then you log out and log back in again. The quickest way to test whether it is all working is to try to run the MySQL client:

[root@host] mysql -V
mysql Ver 14.12 Distrib 5.0.11-beta, for pc-linux-gnu (i686) using readline 5.

If you get an error such as -bash: mysql: command not found, you have not correctly changed the path. If you get the correct version, you have MySQL-Max installed.

There are many other things you would need to do if you were installing a server in a production environment (for example, set a root password, optimize my.cnf), but we do not cover these steps here. If you are not entirely confident with any of these things, you should consult the MySQL manual.

Upgrading a Binary Tarball Setup

To upgrade a binary tarball setup, you follow this process:

  1. Download the new .tar.gz file in /usr/local/ and then extract it.
  2. Make a full backup.
  3. Remove the symlink mysql.
  4. Create a new symlink that points to the new full folder name.
  5. Change the permissions on the new folder.
  6. Restart MySQL.

You can see that this is very easy, and you can also see how easy it is to switch back: All you need to do is replace the mysql symlink with the old one and restart MySQL.

You should also be able to see why we recommend that you not have your data directory in the same place as your binaries. If you do, you need to copy the original data directory over to the new data directory and reset the permissions on it.

Installing from a Binary RPM

Installing from a binary RPM is the easiest method of installing MySQL-Max. Essentially, all you need to do is download and install the RPMs you need. Table 1.1 lists the RPMs you need for each node.

Table 1.1. The RPM Packages Provided by MySQL

Package

Description

SQL

Storage

Management

MySQL-server

The basic MySQL server

Yes

No

No

MySQL-Max

The extra packages that convert MySQL-standard to MySQL-Max

Yes

No

No

MySQL-client

The MySQL client program

Yes

No

No

MySQL-devel

Libraries and header files

Probably

No

No

MySQL-shared

Dynamic client libraries

Probably

No

No

MySQL-bench

Benchmarking tools

Up to you

No

No

MySQL-ndb-storage

Storage node binaries

No

Yes

No

MySQL-ndb-tools

Storage node tools

No

Yes[1]

No

MySQL-ndb-extra

Extra storage node tools

No

Yes

No

MySQL-ndb-management

Management node tools

No

No

Yes

[1] You don't strictly need this or the MySQL-ndb-extra package to run a storage node, but we strongly recommend that you install it because this book often uses packages that appear in all three storage node packages.

Running multiple nodes on one machine is absolutely fine: You just need to install all the packages you might need. For example, to run a storage and SQL node on a server (but not a management node), you should install MySQL-server, MySQL-ndb-storage, MySQL-ndb-tools, MySQL-ndb-extra, and MySQL-Max.

The actual installation process is as simple as obtaining the RPMs you need and installing them. To install all the packages (for SQL, storage, and management nodes as well as benchmarking tools), you use the following commands. Note that this is the process for RPM packages; however, you can easily change this to suit other forms of package, such as those found on OS X. First of all, you obtain the packages:

[user@host] su -
[root@host] cd /tmp/
[root@host] rm -f MySQL-*-5.0.11-0.i386.rpm
[root@host] wget /MySQL-Max-5.0.11-0.i386.rpm
[root@host] wget /MySQL-bench-5.0.11-0.i386.rpm
[root@host] wget /MySQL-client-5.0.11-0.i386.rpm
[root@host] wget /MySQL-devel-5.0.11-0.i386.rpm
[root@host] wget /MySQL-ndb-storage-5.0.11-0.i386.rpm
[root@host] wget /MySQL-ndb-management-5.0.11-0.i386.rpm
[root@host] wget /MySQL-ndb-tools-5.0.11-0.i386.rpm
[root@host] wget /MySQL-ndb-extra-5.0.11-0.i386.rpm

Then you install them. For RPMs, this should be as simple as using the following command:

[root@host] rpm -i MySQL-*-5.0.11-0.i386.rpm

This installs MySQL with every optional extra package. You should be aware that the benchmarking tools require perl-DBI, which you may have to obtain before you can install the RPM.

Upgrading a Binary RPM Setup

To upgrade an RPM setup, you simply download the new RPMs, stop MySQL, and run the following command on each RPM:

rpm -U MySQL-whatever-version.i386.rpm

An issue you may have if you completely remove and reinstall MySQL (that is, if you run rpm -e before installing the new RPM) is that if you have the "cluster lines" that are discussed shortly in the [mysqld] section of /etc/my.cnf file (for example, ndb-connectstring), the commands shown here will fail because the package manager will attempt to restart MySQL after installing the standard MySQL server before it installs MySQL-Max. Without MySQL-Max, you cannot have cluster commands in my.cnf (it throws an error because it has no idea what to do with the parameters), so MySQL will fail to start. The solution is to comment out the offending lines in my.cnf or move my.cnf somewhere else during the upgrade. As soon as all the packages are installed, you can go back to your existing my.cnf.

Compiling from Source

Remember that unless you have a really good reason to install MySQL Cluster by compiling from source, it is probably a bad idea. However, if for some reason you want to compile your own copy, this section provides the steps you should follow. You need GNU bison 1.75 (or newer), make, autoconf 2.58 (or newer), automake 1.8, libtool 1.5, and m4 to run the next set of commands. Even though many operating systems come with their own implementations of make, chances are good that the compilation will fail with strange error messages if you use their versions; therefore, it is highly recommended that you use GNU make (sometimes called gmake) instead.

First, you need to download the source tarball from MySQL.com:

[user@host] su -
[root@host] cd /tmp/
[root@host] wget /mysql-5.0.11-beta.tar.gz
[root@host] tar -zxvf mysql-5.0.11-beta.tar.gz
[root@host] cd mysql-5.0.11-beta

When you have obtained the source code, it is time to compile it. At this stage, you can issue whatever flags you want to the compiler in addition to the basic ones listed here:

[root@host] ./configure --prefix=/usr/local/mysql -with-ndbcluster
[root@host] make
[root@host] make test
[root@host] make install
[root@host] groupadd mysql
[root@host] useradd -g mysql mysql

You then install MySQL and add the mysql user and group.

Now you need to tell MySQL where you want it to store its data. Unless you want it to store the databases in a subdirectory in the same folder as the actual programs (/usr/local/mysql/var), you should create the file /etc/my.cnf, with the following contents:

Note

Remember that it is safest not to store databases in the same folder as the actual programs.

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Next, you need to initialize the tables. This means you need to create the system databases that MySQL needs to run. You should then make sure that these new tables are owned by the mysql user:

[root@host] /usr/local/mysql/bin/mysql_install_db
[root@host] chown -R root:mysql /usr/local/mysql
[root@host] chown -R mysql:mysql /var/lib/mysql

You should now have a working MySQL installation, which you can start like this:

[root@host] /usr/local/mysql/bin/mysqld_safe --user=mysql &

Note

As described earlier in this chapter in the section "Installing MySQL Cluster from a Binary Tarball," you should install the mysql.server script and add the MySQL bin directory to the $PATH variable, but in this case, you find the mysql.server script in the /usr/local/mysql/share/mysql/ folder (not in the support.files folder).

 

Upgrading a Source Installation

To upgrade a source installation, you simply carry out the preceding steps, from su- through make install, but you stop MySQL first and start it again after the installation is complete.





MySQL Clustering
MySQL Clustering
ISBN: 0672328550
EAN: 2147483647
Year: N/A
Pages: 93
Simiral book on Amazon

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