Install mysql-server from ports on FreeBSD

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

Printed from: http://rackerhacker.com/2007/05/27/install-mysql-server-from-ports-on-freebsd/ .
© Major Hayden 2012.

2 Comments   »

  • Jim says:

    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

  • Jim says:

    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.

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this