LAMP Server Setup Pt. 5 – Installing MySQL

I just realized when setting up a second CentOS 5.4 server that MySQL is required for PHP MySQL support (duh) and I didn’t include it in my tutorial so here it is. As an alternative, I’ll be posting a PostgreSQL guide as well, as some users may prefer that (I’ll be using it for my Python/Django projects).

cd /root

# Make sure you get the latest version, this is only the latest as of this writing
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.46.tar.gz/from/http://mysql.mirror.iweb.ca/
tar -xvzf mysql-5.1.46.tar.gz
cd mysql-5.1.46.tar.gz
./configure --prefix=/opt/mysql --exec-prefix=/opt/mysql --with-ssl --with-plugins=innobase,blackhole --with-unix-socket-path=/chroot/httpd/var/lib/mysql/mysql.sock --with-mysqld-libs=/opt/mysql/lib/mysql
make
make install

# For 32 bit operating systems
ln -s /opt/mysql/lib/mysql /usr/lib/mysql

# For 64 bit operating systems
ln -s /opt/mysql/lib/mysql /usr/lib64/mysql

# Make it work with certain programs who look for sockets in the default locations
ln -s /chroot/httpd/var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock 
ln -s /chroot/httpd/var/lib/mysql/mysql.sock /tmp/mysql.sock

Now we need to configure it. Create the directory /opt/mysql/etc and put a my.cnf file in it.

[mysqld]
datadir=/var/lib/mysql
socket=/chroot/httpd/var/lib/mysql/mysql.sock
max_join_size=4M

# User to run as
user=mysql

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=0

# Security settings
set-variable=local-infile=0
skip-networking
bind-address = 127.0.0.1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/chroot/httpd/var/run/mysqld/mysqld.pid

bind-address = 127.0.0.1
default-storage-engine=INNODB

For this to work, /var/lib/mysql and /chroot/httpd/var/run/mysqld and /chroot/httpd/var/lib/mysql should all be owned by mysql:mysql