Installing MySQL Database Server 5.1 using ports collection on FreeBSD

Installing mysql database server on FreeBSD is fairly easy. Here are the steps:
1. Be the root user
password: ********

2. If you don’t have the ports tree, use portsnap to get it
portsnap fetch extract

3. Go to the mysql directory under your ports tree
cd /usr/ports/databases/mysql51-server

4. Compile it
make install clean

5. Edit your /etc/rc.conf to enable the service and add this line

7. Install the primary databases
mysql_install_db --user=mysql

8. Make sure you change the owner and group of /var/db/mysql
chown -R mysql:mysql /var/db/mysql

9. Have a configuration file for your mysql server and edit it to adjust your needs
cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf

10. To try starting the server
/usr/local/etc/rc.d/mysql-server start

Things to remember:

To start
/usr/local/etc/rc.d/mysql-server start

To stop
/usr/local/etc/rc.d/mysql-server stop

To restart mysql
/usr/local/etc/rc.d/mysql-server restart

To check if mysql is running (results may vary specially the PID)
ps ax | grep mysql
64943 p0 R+ 0:00.00 grep mysql
64865 p1 I 0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-f
64891 p1 I 0:00.34 /usr/local/libexec/mysqld --defaults-extra-file=/var/

And don’t forget to set root password and remove the anonymous user account/