Have you tried MySQLTuner yet? It's free and it makes optimizing your MySQL server easier than ever!

Installing mysql on FreeBSD from ports is one of the oddest installations I’ve ever completed. Here’s the step by step:

Get it compiled:
# portinstall mysql50-server
-- OR --
# make -C /usr/ports/databases/mysql50-server install clean

Once it’s installed, copy my-small.cnf, my-medium.cnf or my-huge.cnf to /usr/local/etc/my.cnf:
# cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf

Enable mysql in the rc.conf:
# echo "mysql_enable=\"YES\"" >> /etc/rc.conf

Install the authentication tables:
# mysql_install_db

Last, change the ownership on MySQL’s data directory:
# chown -R mysql:mysql /var/db/mysql

If you miss the last step, you’ll get something ugly like this:
mysqld started
[ERROR] /usr/local/libexec/mysqld: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
[ERROR] /usr/local/libexec/mysqld: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
[ERROR] Fatal error: Can’t open and lock privilege tables: Can’t find file: ‘./mysql/host.frm’ (errno: 13)
mysqld ended

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
2 Responses to “Install mysql-server from ports on FreeBSD”
  1. Thanks for this post! I couldn’t remember the mysql_install_db bit. However, I think that if you add “–user=mysql” to the mysql_install_db command, it will set ownership correctly so you wouldn’t need the chown command. (Also need “–datadir=/path/to/mysql/database_directory” if you want the database somewhere other than /var/db/mysql.) For example:

    # mysql_install_db –user=mysql –datadir=/usr/local/var/db/mysql

    But then you’d also need to add a matching mysql_dbdir line in your rc.conf:

    # echo “mysql_dbdir=\”/usr/local/var/db/mysql\”" >> /etc/rc.conf

  2. Hmm, some kind of formatting goodies here. The long options on the mysql_install_db command have double hyphens preceding them, but they look like em dashes in the post above.

Leave a Reply

You must be logged in to post a comment. Login »