maandag 14 april 2008

MySQL on FreeBSD don't want to start

I installed mysql5 server on my FreeBSD machine.
After adding the following to rc.conf:
mysql_enable="yes"
I notice that mysql is not really running:
netstat -an | grep 3306
did not give any output.

So I started digging.
The log file is by default:
/var/db/mysql/your-FQDN.err

The contest where:
080413 21:10:41 mysqld started
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
080413 21:10:42 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
080413 21:10:43 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
080413 21:10:43 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
080413 21:10:44 InnoDB: Started; log sequence number 0 0
080413 21:10:44 [ERROR] Can't start server : Bind on unix socket: Permission den
ied
080413 21:10:44 [ERROR] Do you already have another mysqld server running on soc
ket: /tmp/mysql.sock ?
080413 21:10:44 [ERROR] Aborting

080413 21:10:44 InnoDB: Starting shutdown...

So the bind of the unix socket is the problem. And it seems to be a permissions problem.

I started googling for this, and some info about /var/local/lib/mysql should be entirely owned by mysql (also group mysql)
I did that, but still without any luck.
There was not already a mysql server running or a file /tmp/mysql.sock

After some time I found out that the /tmp should be chmod 1777 for this to work.
The /var/tmp was like this, but the /tmp was not.
So I did this:
chmod 1777 /tmp
And mysql started just fine.

I have to say that this is probably not the good way of fixing this, probably I have to create an my.cnf file and specify there where the socket should be created.
Linux install by default a my.cnf file, but FreeBSD doesn't seem to be doing this.

If you fixed it you will get this at the bottom of your logfile:
080414 9:21:27 [Note] /usr/local/libexec/mysqld: ready for connections.