Revision of MySQL from Wed, 05/13/2009 - 11:16

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

MySQL is a multithreaded, multi-user SQL database management system which has more than 11 million installations.

Installation
Download the latest version, which was 5.1.34 at the time of writing.

cd /extra/src
wget http://mysql.mirror.rafal.ca/Downloads/MySQL-5.1/mysql-5.1.34.tar.gz
tar zxvf mysql-5.1.34.tar.gz
cd mysql-5.1.34

Add a group and user for the mysql daemon. For a Linux system:

groupadd mysql
useradd -g mysql mysql

At this point, we don't need any advanced options, so our configuration options are simply - just the install path:

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

If configure complains No curses/termcap library found then:

yum install ncurses-devel

If it configures without errors, make and install the binaries:

make
make install

Copy the default preferences file:

cp support-files/my-medium.cnf /etc/my.cnf

Because we compiled and installed as root, we need to change the ownership on the installed files so that the mysql user can access them:

cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .

Create the MySQL data directory and initialize the user tables. In order to get this to run with 5.1.29-rc, I had to edit /etc/my.cnf and comment out the skip-federated line.

bin/mysql_install_db --user=mysql

While most of the installation can be owned by root, the data directory must be owned by the mysql user:

chown -R root .
chown -R mysql var

To test out the installation, start up the MySQL server:

bin/mysqld_safe --user=mysql &

Post-Installation Setup
More detailed instructions available at MySQL's Securing the Initial MySQL Accounts page.
If you prefer, the anonymous account could be removed:

/usr/local/mysql/bin/mysql -u root
DELETE FROM mysql.user WHERE User = '';
FLUSH PRIVILEGES;

Otherwise, assign passwords to the anonymous accounts

/usr/local/mysql/bin/mysql -u root
SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

If you don't know the value of host_name, you can get it using:

SELECT Host, User FROM mysql.user;

Now assign passwords to the root accounts:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

Flush the privileges to make sure our changes take effect:

FLUSH PRIVILEGES;
exit

If you ever forget the the root password, instructions for how to reset it are here.
Stop the MySQL daemon:

killall mysqld

Automatic startup
We're going to use daemontools.
If you haven't already, install daemontools.

Create a directory for the MySQL service:

mkdir -m 1755 /var/service/mysql
cd /var/service/mysql

Create the /var/service/mysql/run script, making sure to change the servername:

#!/bin/sh
exec 2>&1
exec \
/usr/local/bin/setuidgid mysql \
/usr/local/mysql/libexec/mysqld \
--old-passwords \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/var \
--user=mysql \
--pid-file=/usr/local/mysql/var/<servername>.com.pid \
--skip-external-locking \
--port=3306 \
--socket=/tmp/mysql.sock

Make the script executable:

chmod 755 run

Our log script comes from John Simpson's:

mkdir -m 755 log
cd log
wget http://qmail.jms1.net/scripts/service-any-log-run
mv service-any-log-run run
chmod 755 run

Finally, add the service to daemontools by creating the symbolic link in /service

ln -s /var/service/mysql /service/mysql

Confirm that the service is running:

svstat /service/mysql /service/mysql/log

Recent Updates

  • 2 years 1 week ago
  • 2 years 1 week ago
  • 2 years 1 week ago
    php 8.x
  • 2 years 1 week ago
    10.6.7
  • 2 years 2 weeks ago
    Drop Centos 5/6 stuff