Quick guide to help you install the MySQL database server into your FreeBSD machine.

first check that your system does not have the server already installed:

[raistlin@havoc /usr/home/raistlin]$ pkg_info | grep mysql
mysql-client-5.0.75 Multithreaded SQL database (client)

Usually you will have the client installed, it’s used by other packages.

If you have another version of the client installed (4.x, 5.5 or 6.x) I suggest you to install that same server, these steps should do anyway.

Next, if we don’t have the server already installed we can install it in two different ways:

    Using the packages:
    # pkg_add -r mysql50-server
    Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7-stable/Latest/mysql50-server.tbz... Done.
    .
    .
    .
    Using the ports:
    #cd /usr/ports/databases/mysql50-server
    #make install clean

The second option lets you fine tune some parameters of the build process, remeber to write them with the options chosen in /etc/make.conf (This way when performing an upgrade you won’t asked for the build parameters).

Once you jave the server installed run:
# mysql_install_db --user=mysql
Installing MySQL system tables...
090131 22:46:22 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090131 22:46:22 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK
.
.
.
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/bin/mysqladmin -u root password 'new-password'
/usr/local/bin/mysqladmin -u root -h havoc.local password 'new-password'

Alternatively you can run:
/usr/local/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

Now change some permissions and try to run the server:

# chown -R mysql /var/db/mysql/
# chgrp -R mysql /var/db/mysql/
/usr/local/bin/mysqld_safe -user=mysql &
[1] 1380
# Starting mysqld daemon with databases from /var/db/mysql

Then, as told by the install db script we’ll set the mysql root password, note that the mysql root user is not related with the root user in the system, I’ve heard this assumption before.

#/usr/local/bin/mysqladmin -u root password 'secret'
#/usr/local/bin/mysqladmin -u root -h computer.local password 'secret'

The second time we’ll be asked for the password we just set in the first command.

Now we have a running MySQL server, you can configure how it behaves modifying the my.cnf file and configuring the system to start the server at boot time.

Start at boot time:
Add mysql_enable=”YES” to /etc/rc.conf

Set a configuration:
The installation left example configuration files in /usr/local/examples/mysql
Copy of of these: followinf files to /var/db/mysql/my.cnf and modify it to suit your needs:
(This step is optional).

    my-huge.cnf
    my-large.cnf
    my-medim.cnf
    my-small.cnf
    my-innodb-heavy-4G.cnf

Now you have a running MySQL server running and configured.