MySQL

Administrator's Guide

Release 5.0

March 2007


Table of Contents

1. Installation
1.1. Download and Build
1.2. Install
1.3. Automatic startup
2. Replication
2.1. Master configuration
2.2. Slave configuration

Chapter 1. Installation

1.1. Download and Build

Download and save mysql source archive from http://dev.mysql.com/downloads/

cd /usr/local/src
tar -xzf mysql-X.X.X.tar.gz
cd mysql-X.X.X
./configure --prefix=/usr/local/mysql-X.X.X
make
make install

1.2. Install

Install binaries and create required user and directories.

ln -s /usr/local/mysql-X.X.X /usr/local/mysql
groupadd mysql
useradd -g mysql mysql
mkdir -p /var/log/mysql/
chown mysql.mysql /var/log/mysql
mkdir /var/run/mysqld/
chown -R mysql.mysql /var/run/mysqld

Initialize mysql files.

mkdir -p /var/local/mysql/data/
chown -R mysql.mysql /var/local/mysql/data/
su mysql -c "/usr/local/mysql/bin/mysql_install_db --force --datadir=/var/local/mysql/data/"

Create default configuration files.

mkdir -p /etc/mysql
mv /usr/local/mysql/conf /etc/mysql
ln -sf /etc/mysql/conf /usr/local/mysql/
chown -R mysql.mysql /etc/mysql

Add mysql commands in PATH by modifying /etc/profile.

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

1.3. Automatic startup

Copy default startup script.

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql

Adapt it.

basedir=/usr/local/mysql
datadir=/var/local/mysql/data

If you are using dash as the default shell, change the first line with

#!/bin/bash

The configuration file won't be found unless explicitly mentioned. Change the line

	$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &

with

	$bindir/mysqld_safe --defaults-file=/etc/mysql/conf/my.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &

Add execution right and register automatic startup.

chmod a+x /etc/init.d/mysql
update-rc.d -f mysql defaults

Chapter 2. Replication

Detailed steps are available at: http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html

2.1. Master configuration

Give rights to slaves (using mysql client):

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';

Edit configuration file to add an id and logging facilities:

[mysqld]
log-bin=mysql-bin
server-id=1

And restart mysql.

2.2. Slave configuration

Edit configuration file to add an id:

[mysqld]
log-bin=mysql-bin
server-id=N

Setup the replication (using mysql client):

CHANGE MASTER TO MASTER_HOST='master_host_name',
	MASTER_USER='replication_user_name',
	MASTER_PASSWORD='replication_password',
	MASTER_LOG_FILE='',
	MASTER_LOG_POS=4;

and start the slave:

START SLAVE;