要在一个Delphi程序中调用Mysql数据库,查到有个资料如下,待验证,验证后会给出结果。暂时做个标记

已经验证,验证日期:2018.6.18

验证结果:不可行

验证工具:XE7,mysql5.5.51

报错:mysql_connect函数可能已经失效。找不到更新的mysql.pas

用libmySQL.dll(来自于Mysql安装后的文件)
和MySql.pas

以下是mysql.pas

// -----------------------------------------------------------------------------------------------
//
// MySQL Client API for Borland Delphi (version 4 and above)
//
// Pascal Interface Unit for libmySQL.dll, the
// Client Library for MySQL AB's SQL Database Server
//
// This is a literal translation of relevant parts of MySQL AB's
// C header files, mysql.h, mysql_com.h, and mysql_version.h
//
// Copyright (c) 1999-2002 Matthias Fichtner
// (see license.txt for licensing information)
//
// -----------------------------------------------------------------------------------------------
// See mysql.h for MySQL AB's copyright and GPL notice
// -----------------------------------------------------------------------------------------------
//
// 17-Aug-1999 mf Translated mysql.h MySQL 3.22.24
// 19-Aug-1999 mf Corrected some type definitions MySQL 3.22.24
// 20-Aug-1999 mf Finished debugging the unit MySQL 3.22.24
// 18-Sep-1999 mf Code maintenance for release 3.22.26a MySQL 3.22.26a
// 22-Oct-1999 mf Code maintenance for release 3.22.28 MySQL 3.22.28
// 02-Jan-2000 mf Code maintenance for release 3.22.29 MySQL 3.22.29
// 21-Jan-2000 mf Code maintenance for release 3.22.30 MySQL 3.22.30
// 07-Feb-2000 mf Code maintenance for release 3.22.31 MySQL 3.22.31
// 16-Feb-2000 mf Code maintenance for release 3.22.32 MySQL 3.22.32
// 13-Aug-2000 mf Code maintenance for release 3.22.34 MySQL 3.22.34
// 14-Aug-2000 mf Reworked entire unit for first 3.23 release MySQL 3.23.19-beta
// 14-Aug-2000 mf Added mysql_character_set_name() MySQL 3.23.22-beta
// 11-Sep-2000 mf Added IS_NUM_FIELD and INTERNAL_NUM_FIELD MySQL 3.23.24-beta
// 08-Oct-2000 mf Modified TMEM_ROOT, enum_server_command, MySQL 3.23.25-beta
// and INTERNAL_NUM_FIELD
// 01-Nov-2000 mf Code maintenance for release 3.23.27 MySQL 3.23.27-beta
// 25-Nov-2000 mf Code maintenance for release 3.23.28 MySQL 3.23.28-gamma
// 05-Jan-2001 mf Code maintenance for release 3.23.30 MySQL 3.23.30-gamma
// 19-Jan-2001 mf Code maintenance for release 3.23.31 MySQL 3.23.31
// 11-Mar-2001 mf Added functions mysql_real_send_query(), MySQL 3.23.33
// mysql_send_query(), and mysql_reap_query()
// 28-Mai-2001 mf Modified mysql_send_query(), removed MySQL 3.23.38
// mysql_real_send_query(), mysql_reap_query(),
// added mysql_read_query_result(), and fixed
// CLIENT_TRANSACTIONS
// 07-Aug-2001 mf Code maintenance for release 3.23.40 MySQL 3.23.40
// 23-Sep-2001 mf Code maintenance for release 3.23.42 MySQL 3.23.42
// 29-Jan-2002 mf Added libmysql_load(), libmysql_free(), MySQL 3.23.47
// libmysql_status and LIBMYSQL_ constants
// for dynamic loading of libmySQL.dll
// 11-Mar-2002 mf Added MYSQL_OPT_LOCAL_INFILE to mysql_option MySQL 3.23.49
//
// -----------------------------------------------------------------------------------------------
//
// Latest releases of mysql.pas are made available through the
// distribution site at: http://www.fichtner.net/delphi/mysql/
//
// Please send questions, bug reports, and suggestions regarding
// mysql.pas to Matthias Fichtner <mfichtner@fichtner-meyer.com>
//
// See readme.txt for an introduction and documentation.
// See license.txt for licensing information and disclaimer.
//
// -----------------------------------------------------------------------------------------------
// This unit is provided "as is". Use it at your own risk.
// ----------------------------------------------------------------------------------------------- unit mysql; // -----------------------------------------------------------------------------------------------
INTERFACE
// ----------------------------------------------------------------------------------------------- uses
Windows, // Needed for some type definitions
Winsock; // Needed for some type definitions // ----------------
// From mysql.h ...
// ---------------- type
my_bool = byte;
gptr = pChar; type
PUSED_MEM = ^TUSED_MEM; // struct for once_alloc
TUSED_MEM = record
next: PUSED_MEM; // Next block in use
left: longword; // memory left in block
size: longword; // size of block
end; type
error_proc = procedure; type
PMEM_ROOT = ^TMEM_ROOT;
TMEM_ROOT = record
free: PUSED_MEM;
used: PUSED_MEM;
pre_alloc: PUSED_MEM;
min_malloc: longword;
block_size: longword;
error_handler: error_proc;
end; type
my_socket = TSocket; // --------------------
// From mysql_com.h ...
// -------------------- const
NAME_LEN = ; // Field/table name length
HOSTNAME_LENGTH = ;
USERNAME_LENGTH = ;
SERVER_VERSION_LENGTH = ; LOCAL_HOST = 'localhost';
LOCAL_HOST_NAMEDPIPE = '.'; MYSQL_NAMEDPIPE = 'MySQL';
MYSQL_SERVICENAME = 'MySql'; type
enum_server_command = (
COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY,
COM_FIELD_LIST, COM_CREATE_DB, COM_DROP_DB, COM_REFRESH,
COM_SHUTDOWN, COM_STATISTICS,
COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL,
COM_DEBUG, COM_PING, COM_TIME, COM_DELAYED_INSERT,
COM_CHANGE_USER, COM_BINLOG_DUMP,
COM_TABLE_DUMP, COM_CONNECT_OUT
); const
NOT_NULL_FLAG = ; // Field can't be NULL
PRI_KEY_FLAG = ; // Field is part of a primary key
UNIQUE_KEY_FLAG = ; // Field is part of a unique key
MULTIPLE_KEY_FLAG = ; // Field is part of a key
BLOB_FLAG = ; // Field is a blob
UNSIGNED_FLAG = ; // Field is unsigned
ZEROFILL_FLAG = ; // Field is zerofill
BINARY_FLAG = ; // The following are only sent to new clients ENUM_FLAG = ; // field is an enum
AUTO_INCREMENT_FLAG = ; // field is a autoincrement field
TIMESTAMP_FLAG = ; // Field is a timestamp
SET_FLAG = ; // field is a set
NUM_FLAG = ; // Field is num (for clients)
PART_KEY_FLAG = ; // Intern; Part of some key
GROUP_FLAG = ; // Intern: Group field
UNIQUE_FLAG = ; // Intern: Used by sql_yacc REFRESH_GRANT = ; // Refresh grant tables
REFRESH_LOG = ; // Start on new log file
REFRESH_TABLES = ; // close all tables
REFRESH_HOSTS = ; // Flush host cache
REFRESH_STATUS = ; // Flush status variables
REFRESH_THREADS = ; // Flush status variables
REFRESH_SLAVE = ; // Reset master info and restart slave
// thread
REFRESH_MASTER = ; // Remove all bin logs in the index
// and truncate the index // The following can't be set with mysql_refresh() REFRESH_READ_LOCK = ; // Lock tables for read
REFRESH_FAST = ; // Intern flag CLIENT_LONG_PASSWORD = ; // new more secure passwords
CLIENT_FOUND_ROWS = ; // Found instead of affected rows
CLIENT_LONG_FLAG = ; // Get all column flags
CLIENT_CONNECT_WITH_DB = ; // One can specify db on connect
CLIENT_NO_SCHEMA = ; // Don't allow database.table.column
CLIENT_COMPRESS = ; // Can use compression protcol
CLIENT_ODBC = ; // Odbc client
CLIENT_LOCAL_FILES = ; // Can use LOAD DATA LOCAL
CLIENT_IGNORE_SPACE = ; // Ignore spaces before '('
CLIENT_INTERACTIVE = ; // This is an interactive client
CLIENT_SSL = ; // Switch to SSL after handshake
CLIENT_IGNORE_SIGPIPE = ; // IGNORE sigpipes
CLIENT_TRANSACTIONS = ; // Client knows about transactions SERVER_STATUS_IN_TRANS = ; // Transaction has started
SERVER_STATUS_AUTOCOMMIT = ; // Server in auto_commit mode MYSQL_ERRMSG_SIZE = ;
NET_READ_TIMEOUT = ; // Timeout on read
NET_WRITE_TIMEOUT = ; // Timeout on write
NET_WAIT_TIMEOUT = **; // Wait for new query type
PVio = ^TVio;
TVio = record
end; type
PNET = ^TNET;
TNET = record
vio: PVio;
fd: my_socket;
fcntl: longint;
buff, buff_end, write_pos, read_pos: pByte;
last_error: array [..MYSQL_ERRMSG_SIZE - ] of char;
last_errno, max_packet, timeout, pkt_nr: longword;
error: byte;
return_errno, compress: my_bool;
no_send_ok: my_bool; // needed if we are doing several
// queries in one command ( as in LOAD TABLE ... FROM MASTER ),
// and do not want to confuse the client with OK at the wrong time
remain_in_buf, length, buf_length, where_b: longword;
return_status: pLongword;
reading_or_writing: byte;
save_char: char;
end; const
packet_error: longword = $ffffffff; const
FIELD_TYPE_DECIMAL = ;
FIELD_TYPE_TINY = ;
FIELD_TYPE_SHORT = ;
FIELD_TYPE_LONG = ;
FIELD_TYPE_FLOAT = ;
FIELD_TYPE_DOUBLE = ;
FIELD_TYPE_NULL = ;
FIELD_TYPE_TIMESTAMP = ;
FIELD_TYPE_LONGLONG = ;
FIELD_TYPE_INT24 = ;
FIELD_TYPE_DATE = ;
FIELD_TYPE_TIME = ;
FIELD_TYPE_DATETIME = ;
FIELD_TYPE_YEAR = ;
FIELD_TYPE_NEWDATE = ;
FIELD_TYPE_ENUM = ;
FIELD_TYPE_SET = ;
FIELD_TYPE_TINY_BLOB = ;
FIELD_TYPE_MEDIUM_BLOB = ;
FIELD_TYPE_LONG_BLOB = ;
FIELD_TYPE_BLOB = ;
FIELD_TYPE_VAR_STRING = ;
FIELD_TYPE_STRING = ; const
FIELD_TYPE_CHAR = FIELD_TYPE_TINY; // For compability
FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM; // For compability type
enum_field_types = FIELD_TYPE_DECIMAL..FIELD_TYPE_STRING; // ------------------------
// From mysql_version.h ...
// ------------------------ const
PROTOCOL_VERSION = ;
MYSQL_SERVER_VERSION = '3.23.49';
MYSQL_SERVER_SUFFIX = '';
FRM_VER = ;
MYSQL_VERSION_ID = ;
MYSQL_PORT = ;
MYSQL_UNIX_ADDR = '/tmp/mysql.sock'; // ----------------
// From mysql.h ...
// ---------------- function IS_PRI_KEY(n: longword): boolean;
function IS_NOT_NULL(n: longword): boolean;
function IS_BLOB(n: longword): boolean;
function IS_NUM(t: longword): boolean; type
PMYSQL_FIELD = ^TMYSQL_FIELD;
TMYSQL_FIELD = record
name: pChar; // Name of column
table: pChar; // Table of column if column was a field
def: pChar; // Default value (set by mysql_list_fields)
_type: enum_field_types; // Type of field. Se mysql_com.h for types
length: longword; // Width of column
max_length: longword; // Max width of selected set
flags: longword; // Div flags
decimals: longword; // Number of decimals in field
end; function IS_NUM_FIELD(f: PMYSQL_FIELD): boolean;
function INTERNAL_NUM_FIELD(f: PMYSQL_FIELD): boolean; type
PMYSQL_ROW = ^TMYSQL_ROW; // return data as array of strings
TMYSQL_ROW = array[..MaxInt div SizeOf(pChar) - ] of pChar; type
MYSQL_FIELD_OFFSET = longword; // offset to current field type
my_ulonglong = int64; const
MYSQL_COUNT_ERROR: my_ulonglong = not ; type
PMYSQL_ROWS = ^TMYSQL_ROWS;
TMYSQL_ROWS = record
next: PMYSQL_ROWS; // list of rows
data: PMYSQL_ROW;
end; type
MYSQL_ROW_OFFSET = PMYSQL_ROWS; // offset to current row type
PMYSQL_DATA = ^TMYSQL_DATA;
TMYSQL_DATA = record
rows: my_ulonglong;
fields: longword;
data: PMYSQL_ROWS;
alloc: TMEM_ROOT;
end; type
PMYSQL_OPTIONS = ^TMYSQL_OPTIONS;
TMYSQL_OPTIONS = record
connect_timeout, client_flag: longword;
compress, named_pipe: my_bool;
port: longword;
host, init_command, user, password, unix_socket, db: pChar;
my_cnf_file, my_cnf_group, charset_dir, charset_name: pChar;
use_ssl: my_bool; // if to use SSL or not
ssl_key: pChar; // PEM key file
ssl_cert: pChar; // PEM cert file
ssl_ca: pChar; // PEM CA file
ssl_capath: pChar; // PEM directory of CA-s?
end; type
mysql_option = (
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME,
MYSQL_OPT_LOCAL_INFILE
); type
mysql_status = (
MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT,
MYSQL_STATUS_USE_RESULT
); type
PMYSQL_FIELDS = ^TMYSQL_FIELDS;
TMYSQL_FIELDS = array[..MaxInt div SizeOf(TMYSQL_FIELD) - ] of TMYSQL_FIELD; type
PCHARSET_INFO = ^TCHARSET_INFO;
TCHARSET_INFO = record
// Omitted: Structure not necessarily needed.
// Definition of struct charset_info_st can be
// found in include/m_ctype.h
end; type
PMYSQL = ^TMYSQL;
TMYSQL = record
net: TNET; // Communication parameters
connector_fd: gptr; // ConnectorFd for SSL
host, user, passwd, unix_socket, server_version, host_info, info, db: pChar;
port, client_flag, server_capabilities: longword;
protocol_version: longword;
field_count: longword;
server_status: longword;
thread_id: longword; // Id for connection in server
affected_rows: my_ulonglong;
insert_id: my_ulonglong; // id if insert on table with NEXTNR
extra_info: my_ulonglong; // Used by mysqlshow
packet_length: longword;
status: mysql_status;
fields: PMYSQL_FIELDS;
field_alloc: TMEM_ROOT;
free_me: my_bool; // If free in mysql_close
reconnect: my_bool; // set to 1 if automatic reconnect
options: TMYSQL_OPTIONS;
scramble_buff: array [..] of char;
charset: PCHARSET_INFO;
server_language: longword;
end; type
PMYSQL_RES = ^TMYSQL_RES;
TMYSQL_RES = record
row_count: my_ulonglong;
field_count, current_field: longword;
fields: PMYSQL_FIELDS;
data: PMYSQL_DATA;
data_cursor: PMYSQL_ROWS;
field_alloc: TMEM_ROOT;
row: PMYSQL_ROW; // If unbuffered read
current_row: PMYSQL_ROW; // buffer to current row
lengths: pLongword; // column lengths of current row
handle: PMYSQL; // for unbuffered reads
eof: my_bool; // Used my mysql_fetch_row
end; // Functions to get information from the MYSQL and MYSQL_RES structures
// Should definitely be used if one uses shared libraries var
mysql_num_rows: function(res: PMYSQL_RES): my_ulonglong; stdcall;
mysql_num_fields: function(res: PMYSQL_RES): longword; stdcall;
mysql_eof: function(res: PMYSQL_RES): my_bool; stdcall;
mysql_fetch_field_direct: function(res: PMYSQL_RES; fieldnr: longword): PMYSQL_FIELD; stdcall;
mysql_fetch_fields: function(res: PMYSQL_RES): PMYSQL_FIELDS; stdcall;
mysql_row_tell: function(res: PMYSQL_RES): PMYSQL_ROWS; stdcall;
mysql_field_tell: function(res: PMYSQL_RES): longword; stdcall; var
mysql_field_count: function(_mysql: PMYSQL): longword; stdcall;
mysql_affected_rows: function(_mysql: PMYSQL): my_ulonglong; stdcall;
mysql_insert_id: function(_mysql: PMYSQL): my_ulonglong; stdcall;
mysql_errno: function(_mysql: PMYSQL): longword; stdcall;
mysql_error: function(_mysql: PMYSQL): pChar; stdcall;
mysql_info: function(_mysql: PMYSQL): pChar; stdcall;
mysql_thread_id: function(_mysql: PMYSQL): longword; stdcall;
mysql_character_set_name: function(_mysql: PMYSQL): pChar; stdcall; type
PMYSQL_LENGTHS = ^TMYSQL_LENGTHS;
TMYSQL_LENGTHS = array[..MaxInt div SizeOf(longword) - ] of longword; type
extend_buffer_func = function(void: pointer; _to: pChar; length: pLongword): pChar; var
mysql_init: function(_mysql: PMYSQL): PMYSQL; stdcall;
{$IFDEF HAVE_OPENSSL}
mysql_ssl_set: function(_mysql: PMYSQL; const key, cert, ca, capath: pChar): longint; stdcall;
mysql_ssl_cipher: function(_mysql: PMYSQL): pChar; stdcall;
mysql_ssl_clear: function(_mysql: PMYSQL): longint; stdcall;
{$ENDIF} // HAVE_OPENSSL
mysql_connect: function(_mysql: PMYSQL; const host, user, passwd: pChar): PMYSQL; stdcall;
mysql_change_user: function(_mysql: PMYSQL; const user, passwd, db: pChar): my_bool; stdcall;
mysql_real_connect: function(_mysql: PMYSQL; const host, user, passwd, db: pChar; port: longword; const unix_socket: pChar; clientflag: longword): PMYSQL; stdcall;
mysql_close: procedure(sock: PMYSQL); stdcall;
mysql_select_db: function(_mysql: PMYSQL; const db: pChar): longint; stdcall;
mysql_query: function(_mysql: PMYSQL; const q: pChar): longint; stdcall;
mysql_send_query: function(_mysql: PMYSQL; const q: pChar; length: longword): longint; stdcall;
mysql_read_query_result: function(_mysql: PMYSQL): longint; stdcall;
mysql_real_query: function(_mysql: PMYSQL; const q: pChar; length: longword): longint; stdcall;
mysql_create_db: function(_mysql: PMYSQL; const DB: pChar): longint; stdcall;
mysql_drop_db: function(_mysql: PMYSQL; const DB: pChar): longint; stdcall;
mysql_shutdown: function(_mysql: PMYSQL): longint; stdcall;
mysql_dump_debug_info: function(_mysql: PMYSQL): longint; stdcall;
mysql_refresh: function(_mysql: PMYSQL; refresh_options: longword): longint; stdcall;
mysql_kill: function(_mysql: PMYSQL; pid: longword): longint; stdcall;
mysql_ping: function(_mysql: PMYSQL): longint; stdcall;
mysql_stat: function(_mysql: PMYSQL): pChar; stdcall;
mysql_get_server_info: function(_mysql: PMYSQL): pChar; stdcall;
mysql_get_client_info: function: pChar; stdcall;
mysql_get_host_info: function(_mysql: PMYSQL): pChar; stdcall;
mysql_get_proto_info: function(_mysql: PMYSQL): longword; stdcall;
mysql_list_dbs: function(_mysql: PMYSQL; const wild: pChar): PMYSQL_RES; stdcall;
mysql_list_tables: function(_mysql: PMYSQL; const wild: pChar): PMYSQL_RES; stdcall;
mysql_list_fields: function(_mysql: PMYSQL; const table, wild: pChar): PMYSQL_RES; stdcall;
mysql_list_processes: function(_mysql: PMYSQL): PMYSQL_RES; stdcall;
mysql_store_result: function(_mysql: PMYSQL): PMYSQL_RES; stdcall;
mysql_use_result: function(_mysql: PMYSQL): PMYSQL_RES; stdcall;
mysql_options: function(_mysql: PMYSQL; option: mysql_option; const arg: pChar): longint; stdcall;
mysql_free_result: procedure(result: PMYSQL_RES); stdcall;
mysql_data_seek: procedure(result: PMYSQL_RES; offset: my_ulonglong); stdcall;
mysql_row_seek: function(result: PMYSQL_RES; offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET; stdcall;
mysql_field_seek: function(result: PMYSQL_RES; offset: MYSQL_FIELD_OFFSET): MYSQL_FIELD_OFFSET; stdcall;
mysql_fetch_row: function(result: PMYSQL_RES): PMYSQL_ROW; stdcall;
mysql_fetch_lengths: function(result: PMYSQL_RES): PMYSQL_LENGTHS; stdcall;
mysql_fetch_field: function(result: PMYSQL_RES): PMYSQL_FIELD; stdcall;
mysql_escape_string: function(_to: pChar; const from: pChar; from_length: longword): longword; stdcall;
mysql_real_escape_string: function(_mysql: PMYSQL; _to: pChar; const from: pChar; length: longword): longword; stdcall;
mysql_debug: procedure(const debug: pChar); stdcall;
mysql_odbc_escape_string: function(_mysql: PMYSQL; _to: pChar; to_length: longword; const from: pChar; from_length: longword; param: pointer; extend_buffer: extend_buffer_func): pChar; stdcall;
myodbc_remove_escape: procedure(_mysql: PMYSQL; name: pChar); stdcall;
mysql_thread_safe: function: longword; stdcall; function mysql_reload(_mysql: PMySQL): longint; // Status codes for libmySQL.dll const
LIBMYSQL_UNDEFINED = ; // libmysql_load() has not yet been called
LIBMYSQL_MISSING = ; // No suitable DLL could be located
LIBMYSQL_INCOMPATIBLE = ; // A DLL was found but it is not compatible
LIBMYSQL_READY = ; // The DLL was loaded successfully var
libmysql_handle: HMODULE = ;
libmysql_status: byte = LIBMYSQL_UNDEFINED; function libmysql_load(name: pChar): byte;
procedure libmysql_free; // -----------------------------------------------------------------------------------------------
IMPLEMENTATION
// ----------------------------------------------------------------------------------------------- function IS_PRI_KEY(n: longword): boolean;
begin
Result := (n and PRI_KEY_FLAG) = PRI_KEY_FLAG;
end; function IS_NOT_NULL(n: longword): boolean;
begin
Result := (n and NOT_NULL_FLAG) = NOT_NULL_FLAG;
end; function IS_BLOB(n: longword): boolean;
begin
Result := (n and BLOB_FLAG) = BLOB_FLAG;
end; function IS_NUM(t: longword): boolean;
begin
Result := (t <= FIELD_TYPE_INT24) or (t = FIELD_TYPE_YEAR);
end; function IS_NUM_FIELD(f: PMYSQL_FIELD): boolean;
begin
Result := (f.flags and NUM_FLAG) = NUM_FLAG;
end; function INTERNAL_NUM_FIELD(f: PMYSQL_FIELD): boolean;
begin
Result := (((f._type <= FIELD_TYPE_INT24) and ((f._type <> FIELD_TYPE_TIMESTAMP) or (f.length = ) or (f.length = ))) or (f._type = FIELD_TYPE_YEAR));
end; function mysql_reload(_mysql: PMYSQL): longint;
begin
Result := mysql_refresh(_mysql, REFRESH_GRANT);
end; function libmysql_load(name: pChar): byte; procedure assign_proc(var proc: FARPROC; name: pChar);
begin
proc := GetProcAddress(libmysql_handle, name);
if proc = nil then libmysql_status := LIBMYSQL_INCOMPATIBLE;
end; begin
libmysql_free;
if name = nil then name := 'libmysql.dll';
libmysql_handle := LoadLibrary(name);
if libmysql_handle = then libmysql_status := LIBMYSQL_MISSING
else begin
libmysql_status := LIBMYSQL_READY;
assign_proc(@mysql_num_rows, 'mysql_num_rows');
assign_proc(@mysql_num_fields, 'mysql_num_fields');
assign_proc(@mysql_eof, 'mysql_eof');
assign_proc(@mysql_fetch_field_direct, 'mysql_fetch_field_direct');
assign_proc(@mysql_fetch_fields, 'mysql_fetch_fields');
assign_proc(@mysql_row_tell, 'mysql_row_tell');
assign_proc(@mysql_field_tell, 'mysql_field_tell');
assign_proc(@mysql_field_count, 'mysql_field_count');
assign_proc(@mysql_affected_rows, 'mysql_affected_rows');
assign_proc(@mysql_insert_id, 'mysql_insert_id');
assign_proc(@mysql_errno, 'mysql_errno');
assign_proc(@mysql_error, 'mysql_error');
assign_proc(@mysql_info, 'mysql_info');
assign_proc(@mysql_thread_id, 'mysql_thread_id');
assign_proc(@mysql_character_set_name, 'mysql_character_set_name');
assign_proc(@mysql_init, 'mysql_init');
{$IFDEF HAVE_OPENSSL}
assign_proc(@mysql_ssl_set, 'mysql_ssl_set');
assign_proc(@mysql_ssl_cipher, 'mysql_ssl_cipher');
assign_proc(@mysql_ssl_clear, 'mysql_ssl_clear');
{$ENDIF} // HAVE_OPENSSL
assign_proc(@mysql_connect, 'mysql_connect');
assign_proc(@mysql_change_user, 'mysql_change_user');
assign_proc(@mysql_real_connect, 'mysql_real_connect');
assign_proc(@mysql_close, 'mysql_close');
assign_proc(@mysql_select_db, 'mysql_select_db');
assign_proc(@mysql_query, 'mysql_query');
assign_proc(@mysql_send_query, 'mysql_send_query');
assign_proc(@mysql_read_query_result, 'mysql_read_query_result');
assign_proc(@mysql_real_query, 'mysql_real_query');
assign_proc(@mysql_create_db, 'mysql_create_db');
assign_proc(@mysql_drop_db, 'mysql_drop_db');
assign_proc(@mysql_shutdown, 'mysql_shutdown');
assign_proc(@mysql_dump_debug_info, 'mysql_dump_debug_info');
assign_proc(@mysql_refresh, 'mysql_refresh');
assign_proc(@mysql_kill, 'mysql_kill');
assign_proc(@mysql_ping, 'mysql_ping');
assign_proc(@mysql_stat, 'mysql_stat');
assign_proc(@mysql_get_server_info, 'mysql_get_server_info');
assign_proc(@mysql_get_client_info, 'mysql_get_client_info');
assign_proc(@mysql_get_host_info, 'mysql_get_host_info');
assign_proc(@mysql_get_proto_info, 'mysql_get_proto_info');
assign_proc(@mysql_list_dbs, 'mysql_list_dbs');
assign_proc(@mysql_list_tables, 'mysql_list_tables');
assign_proc(@mysql_list_fields, 'mysql_list_fields');
assign_proc(@mysql_list_processes, 'mysql_list_processes');
assign_proc(@mysql_store_result, 'mysql_store_result');
assign_proc(@mysql_use_result, 'mysql_use_result');
assign_proc(@mysql_options, 'mysql_options');
assign_proc(@mysql_free_result, 'mysql_free_result');
assign_proc(@mysql_data_seek, 'mysql_data_seek');
assign_proc(@mysql_row_seek, 'mysql_row_seek');
assign_proc(@mysql_field_seek, 'mysql_field_seek');
assign_proc(@mysql_fetch_row, 'mysql_fetch_row');
assign_proc(@mysql_fetch_lengths, 'mysql_fetch_lengths');
assign_proc(@mysql_fetch_field, 'mysql_fetch_field');
assign_proc(@mysql_escape_string, 'mysql_escape_string');
assign_proc(@mysql_real_escape_string, 'mysql_real_escape_string');
assign_proc(@mysql_debug, 'mysql_debug');
assign_proc(@mysql_odbc_escape_string, 'mysql_odbc_escape_string');
assign_proc(@myodbc_remove_escape, 'myodbc_remove_escape');
assign_proc(@mysql_thread_safe, 'mysql_thread_safe');
end;
Result := libmysql_status;
end; procedure libmysql_free;
begin
if libmysql_handle <> then FreeLibrary(libmysql_handle);
libmysql_handle := ;
libmysql_status := LIBMYSQL_UNDEFINED;
end; // -----------------------------------------------------------------------------------------------
INITIALIZATION
// ----------------------------------------------------------------------------------------------- begin
{$IFNDEF DONT_LOAD_DLL}
libmysql_load(nil);
{$ENDIF} // DONT_LOAD_DLL
end; // -----------------------------------------------------------------------------------------------
FINALIZATION
// ----------------------------------------------------------------------------------------------- begin
libmysql_free;
end; end.

连接本机mysql的例子:

// uses mysql;   //当前目录要有libmySQL.dll,当然,放在系统目录也可以,这个文件在mysql安装目录里有
procedure TForm1.Button1Click(Sender: TObject);
var
Row: PMYSQL_ROW;
MResult: PMYSQL_RES;
dbh:PMYSQL;
tables:string;
begin
dbh := mysql_init(nil);
if dbh=nil then begin showmessage('初始化MySQL对象失败。'); exit; end;
if nil=mysql_connect(dbh,'localhost','root','') then
begin
Memo1.lines.Add(mysql_error(dbh)); exit;
end;
if <>mysql_select_db(dbh,'chemdbs') then
begin
Memo1.Lines.Add(mysql_error(dbh));
mysql_close(dbh); exit;
end;
tables:='maildb';
mysql_query(dbh,PChar('select id,dw,em,lxr,flg from '+tables+' where flg=0 limit 0,30000'));
MResult := mysql_use_result(dbh);
EMList.Clear;
Ems.Clear; Sta.Clear;
repeat
Row := mysql_fetch_row(MResult);
if Row<>nil then begin
Ems.Add(Row[] + ',' + Row[] + ',' + Row[]);
Sta.Add('');
EMList.Items.Add.Caption :='';
end;
until Row=nil;
mysql_free_result(MResult);
mysql_close(dbh);
Logs.Lines.Add(inttostr(Ems.Count) + 'Record Read');
end;

1、基于安全考虑,很多mysql服务器只允许本机连接,检查你的linux上的mysql是否允许外部连接。
2、程序中只要mysql_connect(dbh,'localhost','root','') 后面3个参数正确就可以,主机地址、用户名、密码。即可连接到其它服务器上的MySQL
3、移动数据只要把mysql安装目录下的data目录下的某个目录移走,一个目录是一个数据库。

libmysql.dll 版本是:3.23.49
mysql.pas 版本是3.23.49
后台mysql服务器版本是3.23.47 for win2000及3.23.42 for sco openserver 5.0.6
经测试:运行正确,非常好.

把ado,bde,odbc扔到垃圾堆去吧.

参考:https://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html

Delphi连接MySql(待测试验证,使用mysql.pas未通过)的更多相关文章

  1. MySQL Router 测试使用 转

    MySQL Router 测试使用 . 特性 MySQL Router 并没有包括一些特别新的特性, 总体上看中规中矩, 不过 first-available 和插件两个特性挺有意思, 后续会进行讲解 ...

  2. mysql基础测试

    mysql基础测试 测试原因   为什么需要做性能测试 模拟比当前系统更高的负载,找出性能瓶颈 重现线上异常 测试不同硬件软件配置 规划未来的业务增长   测试分类   性能测试的分类 设备层的测试 ...

  3. delphi 连接mysql

    Delphi连接MySQL真麻烦,研究了一天,从网上找了无数文章,下载了无数插件都没解决.最后返璞归真,老老实实用ADO来连接,发现也不是很顺利,但最终还是连接成功了.多少有点心得:ADO各个组件的作 ...

  4. delphi连接mysql不用添加DSN(mysql connector odbc 5.1版)

    一.下载安装mysql驱动http://mysql.com/downloads/connector/odbc/二.添加adoconnection,adoquery,使用以下连接字符串http://ww ...

  5. Hadoop第9周练习—Hive部署测试(含MySql部署)

    1.1 2 :搭建Hive环境 内容 2.2 3  运行环境说明 1.1  硬软件环境 线程,主频2.2G,6G内存 l  虚拟软件:VMware® Workstation 9.0.0 build-8 ...

  6. jdbc连接阿里云服务器上的MySQL数据库 及 数据库IP限制

    问题1:Jdbc 如何连接阿里云服务器上的MySQL数据库? 解决: 上截图: 其中IP是阿里云服务器的公网IP地址. 问题2:   刚开始接手开发的时候,使用Navicat连接阿里云服务器上的数据后 ...

  7. mysql 通过测试'for update',深入了解行锁、表锁、索引

    mysql 通过测试'for update',深入了解行锁.表锁.索引 条件 FOR UPDATE 仅适用于InnoDB存储引擎,且必须在事务区块(BEGIN/COMMIT)中才能生效. mysql默 ...

  8. sysbench安装、对Mysql压力测试、结果解读及mysql数据库跟踪优化

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试. sysbench支持以下几种测试模式: 1.CPU运算性能 2.磁盘IO性能 3.调度程序性 ...

  9. 【JMeter】JMeter进行简单的数据库(mysql)压力测试

    JMeter进行简单的数据库(mysql)压力测试 1.点击测试计划,再点击“浏览”,把JDBC驱动添加进来: 注:JDBC驱动一般的位置在java的安装地址下,路径类似于:    \java\jre ...

随机推荐

  1. [Swift]LeetCode587. 安装栅栏 | Erect the Fence

    There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden ...

  2. [Swift]LeetCode747. 至少是其他数字两倍的最大数 | Largest Number At Least Twice of Others

    In a given integer array nums, there is always exactly one largest element. Find whether the largest ...

  3. 美国5G:初步上线玩砸,信号难寻和4G无差别

    事件背景: 自从美国最高联邦法院给美国国会立法机关送去了传票之后,至今为止还暂时没有动静.传票限期两个月,不开庭就视为自动败诉,目前离最后的期限应该还有一个月的时间,静心等待结果就好. 不过这段时间, ...

  4. Unable to preventDefault inside passive event listener due to target being treated as passive

    Unable to preventDefault inside passive event listener due to target being treated as passive 今天在做项目 ...

  5. .NET Core实战项目之CMS 第三章 入门篇-源码解析配置文件及依赖注入

    作者:依乐祝 原文链接:https://www.cnblogs.com/yilezhu/p/9998021.html 写在前面 上篇文章我给大家讲解了ASP.NET Core的概念及为什么使用它,接着 ...

  6. 采坑:python base64

    需求:  读取文本内容,对字符串进行base64加密 >>> str = 'aaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbb\nccc ...

  7. 一纸理解JVM

    JVM,JDK,JRE定义 JVM是Java Virtual Machine(Java虚拟机)的缩写. JDK是Java Development Kit JAVA语言开发工具箱(JAVA核心) JRE ...

  8. Java基础1:深入理解Java面向对象三大特性

    更多内容请关注微信公众号[Java技术江湖] 这是一位阿里 Java 工程师的技术小站,作者黄小斜,专注 Java 相关技术:SSM.SpringBoot.MySQL.分布式.中间件.集群.Linux ...

  9. SQL修改表字段,加附属属性

    GO Go EXEC sys.[sp_addextendedproperty] @name = 'MS_Description',@value = '是否填写表单',@level0type = 'SC ...

  10. Java开发知识之Java中的泛型

    Java开发知识之Java中的泛型 一丶简介什么是泛型. 泛型就是指泛指任何数据类型. 就是把数据类型用泛型替代了. 这样是可以的. 二丶Java中的泛型 Java中,所有类的父类都是Object类. ...