Mysql_udf_unix_timestamp_ms is a project mainly written in C, it's free.
Implementation of UNIX_TIMESTAMP() that returns UNIX time since epoch with sub-second precision (float)
Implementation of UNIX_TIMESTAMP() that returns UNIX time since epoch with sub-second precision (float).
mysql> select unix_timestamp_ms() 1000 / 1000; +-----------------------------------+ | unix_timestamp_ms() 1000 / 1000 | +-----------------------------------+ | 1276753745.7377 | +-----------------------------------+ 1 row in set (0.00 sec)
Build and install extension library, see, for example: http://dev.mysql.com/doc/refman/5.0/en/udf-compiling.html a) Mac OS X with MacPorts:
gcc -bundle -bundle_loader /opt/local/libexec/mysqld -o lib_udf_unix_timestamp_ms.so lib_udf_unix_timestamp_ms.c -I/opt/local/include/mysql5/mysql
sudo cp lib_udf_unix_timestamp_ms.so /opt/local/lib/mysql5/mysql/plugin/
b) Linux (CentOS)
get lib_udf_unix_timestamp_ms.{c,sql}
gcc -shared -fPIC -o lib_udf_unix_timestamp_ms.so lib_udf_unix_timestamp_ms.c -I /usr/include/mysql/
su
cp lib_udf_unix_timestamp_ms.so /usr/lib
/sbin/ldconfig
Install function into MySQL: mysql mysql < lib_udf_unix_timestamp_ms.sql
You're free to use, distribute and modify this code. It is public domain.