MySQL Source Installation

Generic install for MySQL.

Add mysql group and user:

groupadd mysql
useradd -g mysql mysql

Target install base:

/var/run/mysqld/ - mysqld.sock
/usr/bin - binaries
/etc/mysql - configuration
/usr/lib/ - libraries
/usr/lib/mysql/plugin - plugins
/usr/sbin - mysqld binary
/usr/share/doc/percona-server-5.5/ - docs
/usr/share - shares
/usr/share/man - man pages
/usr/share/mysql - charsets

Unpack tarball and start build for a 5.5 install:

rm -f CMakeCache.txt
cmake . -DCMAKE_INSTALL_PREFIX=/usr -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc/mysql -DINSTALL_BINDIR=bin -DINSTALL_DOCDIR=share/doc/mysql-5.5 -DINSTALL_DOCREADMEDIR=share/doc/mysql-5.5/readme -DINSTALL_INCLUDEDIR=include/mysql -DINSTALL_INFODIR=share/info -DINSTALL_LIBDIR=lib/mysql -DINSTALL_MANDIR=share/man -DINSTALL_MYSQLSHAREDIR=share/mysql -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test -DINSTALL_PLUGINDIR=lib/mysql/plugin -DINSTALL_SBINDIR=libexec -DINSTALL_SCRIPTDIR=bin -DINSTALL_SQLBENCHDIR=share/mysql -DINSTALL_SUPPORTFILESDIR=/usr/share/mysql -DWITHOUT_UNIT_TESTS=1 -DINSTALL_SUPPORTFILESDIR=share/doc/mysql-5.5/support -DWITH_SSL=system
make

Install new init script:

cp /etc/init.d/mysql{,.bak}
cp support-files/mysql.server /etc/init.d/mysql.server

Get the old value for the innodb_log_file_size and update it in the new my.cnf:

mysql information_schema -Bse "select variable_value from session_variables where variable_name = 'innodb_log_file_size';"

Backups, stop server:

mysqldump -A > ~/mysqldump-$(date %+F).sql
/etc/init.d/mysql stop

Setup directories, files and ownership:

mkdir /var/run/mysqld /var/log/mysql
touch /var/run/mysqld/mysqld.{pid,sock} /var/log/mysql/mysql{,-slow}.log
rm -f /var/lib/mysql/mysql.sock /tmp/mysql.sock /var/lib/mysql/mysqld.pid /var/lib/mysql/mysql.sock 
mkdir -p /var/lib/mysql/data
mkdir -p /var/log/mysql
touch /var/log/mysql/mysql{,-slow}.log

Actually install binaries, final setup:

make install
cd /usr
# ./bin/mysql_install_db --datadir=/var/lib/mysql/data
chown -R mysql: /var/lib/mysql/data /var/run/mysqld /var/log/mysql
chmod 2750 /var/log/mysql/*
chmod 0700 /var/lib/mysql/data
cp /etc/my.cnf{,.bak}

Start the server:

tail -f /var/log/mysql/mysql.log
mv /etc/init.d/mysql{.server,}
chmod +x /etc/init.d/mysql
/etc/init.d/mysql start

Create symlinks that would be deleted before now:

ln -s /var/run/mysqld/mysqld.pid /var/lib/mysql/mysqld.pid
ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

Bring databases up to speed:

mysql_upgrade
mysqlcheck -A

Some possible loose ends:

cpan install DBD::MySQL

Add to your php.ini:

pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock