Quick Install MySQL from source distribution

This tutorial will show you on how to install MySQL server from source distribution. I use Slackware for this tutorial but it should be application in other Linux distros (Centos, Ubuntu, Redhat, Fedora, Debian, etc) and BSDs varian (FreeBSD, PC-BSD, NetBSD, and OpenBSD).

Basically the explanation on how to install MySQL is already explained the INSTALL-* files included in the source file. This tutorial is only a quick step and straightforward way because if you are a newbie you will take some times to read the INSTALL-* files.

First download the MySQL source here. At the time this tutorial written, the latest stable version of MySQL is 5.1.37.

Untar, configure and then compile the source. We will install it in /usr/local/mysql5 folder as the target.

Here are the complete steps:

$ tar zxf mysql-5.1.37.tar.gz
$ cd mysql-5.1.37
$ ./configure --prefix=/usr/local/mysql5 --mandir=/usr/local/man
$ make
$ sudo make install

# groupadd mysql
# useradd -g mysql -s /bin/false -c 'MySQL Database' mysql

# cd /usr/local/mysql5
# chown -R mysql .
# chgrp -R mysql .
# ./bin/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql var
# ./bin/mysqld_safe --user=mysql &

Check the MySQL service is now running and LISTEN on 3306 port.

# netstat -atp|grep mysql
tcp        0      0 *:3306    *:*    LISTEN    23767/mysqld

Do not forget to set the root password for MySQL (not system root password) by firing the command below:

# /usr/local/mysql5/bin/mysqladmin -u root password yourpassword

Now you can try to log in to the MySQL server by issuing the command below:

$ /usr/local/mysql5/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.37 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql>