MySQL Driver for REBOL
Download Now!
Size :  25Kb
Level :  Mature
Version :  1.2.1
Date :  12-Jul-2008
Hits : 


This driver will allow you to connect to a MySQL database server, send queries and retrieve resulting recordsets. This driver is 100% written in REBOL and doesn't require any additional library (like libmysql). It works with all REBOL products and on all platforms supported by REBOL ! You only need one file to make it work and it's size is less than 30Kb !

It works by adding a new scheme (mysql://) that enables any REBOL product to talk to a MySQL server. Here are some code examples :

    db: open mysql://root@localhost/books       ; open the connection
    print send-sql db "SELECT * FROM Authors"   ; send a SQL query
    close db                                    ; close the connection

Here's an even greater example using the REBOL read shortcut function :

    ;-- Return the list of tables in 'books' database
    print read mysql://root@localhost/books

    ;-- Open a port, send a SQL query and close the port
    print read/custom mysql://root@localhost/books ["SELECT * FROM Authors"]

Administration commands are also supported :

    print insert db [statistics]
    insert db [shutdown]
    insert db [ping]
    insert db [reload log grant status]

This driver have been designed and especially optimized for REBOL from the ground up ! It takes very little resources and can work with millions of records using the COPY/PART and FIRST functions. This driver is also very fast ! Just try it, you won't believe that it's an interpreted driver !


  • MySQL server v3, v4 and v5 supported.
  • SQL Prepared Statements supported.
  • Server administration commands supported (statistics, reload, process-kill,...).
  • Automatic reconnection to the server if the connection times out.
  • Programmable SQL types <=> REBOL types conversion system.
  • Command-line client included in the archive.
  • Close integration within REBOL (virtual series).
  • Runs unchanged on 18+ OSes : see supported OSes here
  • Compact : 26Kb (for the driver)
  • Open-source : BSD-like license.

Download & Install

Download the latest version and save it in a directory. To install the driver, just uncompress the ZIP archive on your local disk. The driver files are now installed in a directory called mysql-driver/ and you are free to move it and rename it. The archive is composed of 4 files :

%mysql-protocol.r The driver
%mysql.r A command-line MySQL client
%mysql-wrapper.r Gabriele Santilli's MySQL helping pack
%mysql-usage.html Developer's guide

To use the driver, just DO it ! :) :

    >> cd %mysql-driver/
    >> do %mysql-protocol.r
    MySQL protocol loaded

The driver is now loaded and ready to use !


The complete driver documentation is included in the driver's archive. You can also read it online here :

Todo List

  • Improve the command-line client. (add multiline typing support)
  • Make a graphical client and admin tool


  • v.1.2.1 - 12/07/2008
    - Fixed a long standing bug in the reconnection process, now the driver will correctly reset the port state before trying to reconnect.
    - Comments using sharp symbol (#) are now supported in SQL scripts.
    - SQL characters escaping function optimized, now almost 2 times faster.
    - 'sql-escape and 'to-sql are now global functions.
    - MySQL zero dates special values are now converted to 1-jan-0000, instead of throwing an error.

  • v.1.2.0 - 23/09/2007
    - Changed behaviour and syntax of the READ function.
    - Fix for parsing correctly quoted empty strings. (Fix by Oldes)
    - Fix for the driver loosing local flags, like 'flat, 'auto-ping?,... when reconnecting (thanks to Will Arp)
    - Fix a remanence issue on /flat and /raw flags in 'send-sql after automatic reconnection. (thanks to Will Arp)
    - Improved port recovery support after a failed request upon a shutdown server.
    - An init SQL string can now be specified for an opened port.

  • v.1.1.2 - 16/06/2007
    - Fix for an infinite loop issue when the server times out the connection (unix platforms).
    - TCP keepalive option activated by default (for longstanding idle connections).
    - Send-cmd function optimized to be a little bit faster and use less memory.
    - Added new-lines markers to resulting recorsets.
    - Added option to switch on/off new-lines marker through port/locals/newlines? flag.
    - Recycle call removed from read-rows function. Should speed up the results a little bit.
    - Minor source code cleanup.

  • v.1.1.1 - 22/05/2007
    - Multi-statements queries parsing improved. Semi-colons included in quoted strings are now ignored.
    - Email!, url! and other any-string! values are now correctly escaped in prepared statements.
    - Empty block! values are now converted to "()" instead of "(NULL)".

  • v.1.1.0 - 01/05/2007
    - Added 'send-sql global functon (new prefered way of querying the server).
    - Added 'name-fields global function to add column names to a record.
    - Added support for SQL queries with multiple statements separated by a semicolumn.
    - Small fix for buffer and cache sync issue in rare cases.
    - Documentation updated.

  • v.1.0.7 - 01/07/2006
    - Fixes a comptability issue in handshaking with new servers using old passwords format.

  • v.1.0.6 - 10/06/2006
    - Added support for new types: var-char, bit, new-decimal.
    - New property: flat? to allow flat resulting recordsets (one block only).
    - 's added in local context in packet reading rules.
    - Query returning empty sets now returns a runtime created block! instead of a literal one.
    - Reliability improved : random 1043 and 1045 error on connecting now silently handled.
    - Bug fix : cache reading buffer size wasn't always in sync with main buffer. (Thanks to Ammon)
    - Bug fix : 'byte word added to local context
    - Bug fix : port init now correctly handle '?' marker (Thanks to Coccinelle)
    - Bug fix : added a missing 'any call in 'read-packet function (never caused any trouble so far)
    - Upgrade of password authentication to support server v4.1.1+. (Thanks to Petr Krenzelok for his help)
    - Minor additions to support new protocol flags.
    - Bug fix : correct the buffer/cache size synchronization. (Thanks to Hallvard Ystad for its bug report)
    - Patch to 'insert to support molded blocks as args.
    - Sent SQL string can be now be seen in trace mode.
    - Documentation updated.

  • v.0.9.9 - 25/07/2001
    - Date!, time!, money!, binary! and block! types are now converted to SQL.
    - Auto-reconnecting on 'insert calls when server restart or after a timeout.
    - Added flag 'auto-ping? in port/locals
    - Added support for user-defined mySQL types handlers.
    - Added 'change-type-handler function to global context.
    - "?" in password field will ask for hidden password typing.
    - Characters '_ and '% were escaped in inserted strings by error. Fixed.
    - Nasty bug fixed in binary decoding rules. /case refinement added to 'parse calls.
    - Several bug-fixes in Rebol to SQL conversions.
    - Little code clean-up.
    - mySQL client app updated.
    - Added to archive: mysql-wrapper.r from Gabriele Santilli.
    - Documentation updated.

  • v.0.8.6 - 24/05/2001
    - A bug was introduced in 0.8.5 in the handshake process when the handshake fails. Fixed.
    - Multiple opened ports at the same time now supported ! (You can now mix 'open and 'read calls on multiple ports)
    - Some minor code clean-up.

  • v.0.8.5 - 10/03/2001
    - Server admin commands now supported.(see docs)
    - Enhanced low-level I/O. (more robust)
    - Records end pre-fetched. (see docs)
    - Automatic flush of unread records.
    - Inserting rebol values into sql strings supported.(see docs)
    - Little bug in 'read fixed. (Appeared when mixing 'read and 'open calls)
    - Date & time values now converted to Rebol types.
    - 'mysql-cmd suppressed. (not needed anymore)
    - Trace/net is now more verbose.
    - Bug in binary encoding functions fixed.
    - Code clean-up.

  • v.0.8.4 - 12/02/2001
    - Null values conversion bug. Fixed.
    - 'Null now handled at low-level.
    - Added field flags decoding.
    - Some minor code clean-up.

  • v.0.8.3 - 07/02/2001
    - 'first works now ! (see Usage)
    - 'copy just after 'open will timeout. Fixed.

  • v.0.8.2 - 06/02/2001
    - Timeout when no column returned. Fixed
    - matched-rows added to port/locals.
    - 'mysql-cmd added to global context.
    - Bug in binary decoding rules. Fixed.

  • v.0.8.1 - 30/01/2001
    - Now 'read is stable under 2.4.40

  • v.0.8.0 - 29/01/2001
    - First release for /Link users.