Sunday, July 31, 2011

Quick and Easy setup MySQL Server on FreeBSD


One of the first problems that I had was run a MySQL service up and running. A lot of applications that I use and test require a database engine and I don't want to spend time on installing and configuring these. I want to share how to install and run a new installation of MySQL server on FreeBSD 8.2 from the packages repository in a quick and easy matter.

Logged on as root or su to root and run the pkg_add command to fetch MySQL 5.5 Server from the packages repository:

$ pkg_add -r mysql55-server


After finishes installation, just run these commands and you will have a running instance of MySQL:

$ mysql_install_db --user=mysql
$ chown -R mysql /var/db/mysql/
$ chgrp -R mysql /var/db/mysql/
$ /usr/local/bin/mysqld_safe -user=mysql &
$ cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf


If you want to run MySQL only local, yo can modify the file my.cnf copied before and add the following line:

bind-address = 127.0.0.1


To start MySQL for the first time run the following:

$ /usr/local/etc/rc.d/mysql-server onestart


To run mysql each time the machine reboot, add the following line to the file /etc/rc.conf:

mysql-server_start="YES"


You can verify that mysql is running using the ps command:

ps -ax | grep mysql
788 ?? Is 0:00.02 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-f
1054 ?? I 0:01.50 [mysqld]
21113 1 S+ 0:00.00 grep mysql


If you configure the server to run only on localhost, you can verify this with the following comand:

$ sockstat -4 | grep mysql
mysql mysqld 1054 11 tcp4 127.0.0.1:3306 *:*


You have a MySQL instance up and running now.. Remmember that the default user is "root" with blank password, you can login with the command:

$ mysql -u root

and change the password, create databases, tables, etc..


Hope this quick MySQL setup help you and you can spend time testing your applications instead of setting up mysql each time.