program ListDbs;

uses MySQL;

var
  MHandle: PMySQL;
  MRes: PMySQLRes;
  Row: PMySQLRow;
  NumRows, i: LongCard;

begin
  MHandle := MySQLInit (nil);
  if MySQLRealConnect (MHandle, '', '', '', 'test', 0, nil, 0) = nil then
    begin
      WriteLn (StdErr, 'Cannot connect to MySQL Server');
      WriteLn (StdErr, 'Error Code ', MySQLError (MHandle))
    end
  else
    begin
      MRes := MySQLListDbs (MHandle, nil);
      NumRows := MySQLNumRows (MRes);
      WriteLn;
      WriteLn ('list all available databases (I see ', NumRows, ')');
      WriteLn ('==============');
      for i := 0 to NumRows - 1 do
        begin
          Row := MySQLFetchRow (MRes);
          WriteLn (i+1, ') ', CString2String (Row^[0]))
        end;
      MySQLFreeResult (MRes);
      MySQLClose (MHandle)
    end
end.
