AnyDAC
ContentsIndexHome
PreviousUpNext
Connect to MySQL Server

Describes how to connect to MySQL Server.

Group
Links
Supported versions

The AnyDAC native driver supports the MySQL Server Community, Enterprise and Embedded editions version 3.21 and higher. 

 

Windows client software

AnyDAC requires one of the following x86 or x64 libraries:

  • the LIBMYSQL.DLL client library for connecting to MySQL server. Ideally, the version should be equal to the server version.
  • the LIBMYSQLD.DLL embedded server library. See "MySQL Embedded server" chapter below.

You can take them from a server (details) installation Bin folder and put into a folder:

  • listed in your PATH environment variable (for example, <Windows>\SYSTEM32);
  • your application EXE folder;
  • any other folder and specify in AnyDAC\DB\ADDrivers.ini:

 

[MySQL]
VendorLib=<folder>\libmysql.dll

 

When the MySQL client library has not been properly installed, you will get an exception when you try to connect: 

 

[AnyDAC][Phys][MySQL]-314. Cannot load vendor library [libmysql.dll]. The specified module could not be found.
Check [libmysql.dll], which is located in one of the PATH directories or in application EXE directory.

 

Linux client software

AnyDAC requires:

  • the libmysqlclient.so x86 or x64 client library.

To install on Linux use the commands: 

 

sudo apt-get update
sudo apt-get install libmysqlclient16
sudo ln -s /usr/lib/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so

 

Mac OS X client software

AnyDAC requires:

  • the libmysqlclient.dylib x86 client library.

You can download it as Connector/C for Mac OS X (here). And extract it into /usr/local folder, using the command: 

 

sudo tar -C /usr/local -zxvf mysql-connector-c-6.0.2-osx10.5-x86-32bit.tar

 

Driver linkage

To link the driver:

 

Connection definition parameters

To connect to a MySQL DBMS, most applications will need to specify DriverID, Server, Database, User_Name, Password, CharacterSet

 

DriverID=MySQL  

Parameter 
Description 
Example value 
Server 
The TCP/IP address or host name of the server running a MySQL server. 
127.0.0.1 
Port 
The TCP/IP port on which the MySQL server is listening. 
3306 
Database 
Name of the current database for the connection. If the Database is not specified, no current database is set up. 
MyDB 
User_Name 
The MySQL user ID. 
root 
Password 
The MySQL user password. 
 
CharacterSet 
The default character set for the connection. The connection collation becomes the default collation of the character set. See the SET NAMES statement for details. 
cp1251 
Compress 
Specify True to enable network traffic compression. By default, it is set to False
 
UseSSL 
Specify True to enable SSL connection. By default, it is set to False. Setting UseSSL=True requires additionally specify connection definition parameters:
  • SSL_key - is the path name to the key file;
  • SSL_cert - is the path name to the certificate file;
  • SSL_ca - is the path name to the certificate authority file;
  • SSL_capath - is the path name to a directory that contains trusted SSL CA certificates in pem format;
  • SSL_cipher - is a list of permissible ciphers to use for SSL encryption.
For additional details please check MySQL documentation
True 
LoginTimeout 
Controls the amount of time (in seconds) an application waits for a connection attempt to timeout while waiting to establish a connection. 
30 
ReadTimeout 
The timeout in seconds for attempts to read from the server. Each attempt uses this timeout value and there are retries if necessary, so the total effective timeout value is three times the option value. You can set the value so that a lost connection can be detected earlier than the TCP/IP Close_Wait_Timeout value of 10 minutes. This option works only for TCP/IP connections and, prior to MySQL 5.1.12, only for Windows. By default, it is not set. 
WriteTimeout 
The timeout in seconds for attempts to write to the server. Each attempt uses this timeout value and there are net_retry_count retries if necessary, so the total effective timeout value is net_retry_count times the option value. This option works only for TCP/IP connections and, prior to MySQL 5.1.12, only for Windows. By default, it is not set. 
ResultMode 
Controls how to fetch a result set to a client. The default value is Store.
  • Store - fetches all rows right after query execution and stores them on a client, making the server process ready for new requests.
  • Use - rows will be fetched on demand of a client. While not all rows from the result set are fetched, the server cannot handle new requests. It allows to reduce memory usage on very big result sets.
  • Choose - AnyDAC will automatically choose a mode. If the FetchOption.Mode is one of fmAll, fmExactRecsMax, then "Store", otherwise "Use".
 
Use 
TinyIntFormat 
Controls the TINYINT(1) representation. The default value is Boolean.
  • Boolean - TINYINT(1) columns will be represented as dtBoolean.
  • Integer - TINYINT(1) columns will be represented as dtSByte or dtByte.
 
Integer 
MetaDefCatalog 
Default database name. Design time code will exclude the catalog name from the object name if it is equal to MetaDefCatalog. Setting the MetaDefCatalog does not change the current database in the MySQL session. 
MyDB 

 

MySQL Embedded server

Major notes:

  1. All path argument values are using Unix back slashes. You can specify paths relatively to the application EXE folder, that will simplify deployment.
  2. libmysqld.dll and errmsg.sys must be of the same version.
  3. libmysqld.dll v 5.1.34, as probably some other versions, are broken and will not work. Update to other version.
  4. The general MySQL Embedded setup may be hard. For simplified setup see examples later.

 

To prepare your application to work with a MySQL Embedded server, you should take the following actions:

  • Include the TADPhysMySQLDriverLink component into your application. Note, "add argument" means "add argument to TADPhysMySQLDriverLink.EmbeddedArgs list". Optionally you can use driver configuration file.
  • Copy LIBMYSQLD.DLL to the application executable folder. If this folder differs from the application executable folder, add the --basedir=<LIBMYSQLD folder> argument. And set TADPhysMySQLDriverLink.VendorLib to <LIBMYSQLD folder>\LIBMYSQLD.DLL.
  • If only English messages are used, copy share\english\errmsg.sys to <LIBMYSQLD folder> and add the --language=<LIBMYSQLD folder> argument. If multiple language messages are used, copy appropriate folders from share\* to <LIBMYSQLD folder>, preserving directory structure. There is no need to add the --language argument, because <LIBMYSQLD folder>\share\* is the default location.
  • If the used character sets are different from ASCII, copy share\english\charsets to <LIBMYSQLD folder>, preserving directory structure. There is no need to add --character-sets-dir argument, because <LIBMYSQLD folder>\share\charsets is the default location.
  • If the database files are located in different folders than <LIBMYSQLD folder>, add the --datadir=<database files folder> argument.
  • If the InnoDB engine is not used, add the --skip-innodb argument. Otherwise add the --innodb_data_home_dir=<database files folder> argument, where the value is the InnoDB data space directory.
  • If your application will not connect to a remote MySQL server, add the --skip-networking argument.
  • If your application will use external settings file, add the --defaults-file=my.ini argument.
  • If your application will use MySQL plugins, add the --plugin_dir=<plugin folder> argument. Normally plugins are located in <LIBMYSQLD folder>\lib\plugin.
  • Add appropriate arguments to tune performance.

 

To connect to MySQL Embedded server you should not specify Server, Host, Port, User_Name, Password connection definition parameters. If you does not specify --skip-networking argument, then using libmysqld.dll you can connect to the remote MySQL servers, the same as with normal libmysql.dll. 

 

Simple setup example:

  • Charsets: ASCII only
  • Messages: English only
  • Database: the EXE folder
App folder:
  <app>.EXE
  LIBMYSQLD.DLL
  errmsg.sys
  <DB files>
Arguments:
  --language=./
  --skip-innodb
  --skip-networking

 

Extended setup example:

  • Charsets: multiple
  • Messages: multiple
  • Database: "data" subfolder
App folder:
  <app>.EXE
  LIBMYSQLD.DLL
  share\*
  share\charsets
  data\*
  data\<DB files>
Arguments:
  --datadir=./data
  --skip-innodb
  --skip-networking

 

Usage cases
  • Connect to a locally running server, listening on the default (3306) port:

 

DriverID=MySQL
Database=addemo
User_Name=root
Password=

 

  • Connect to a remote server, listening on a non-default port, using Unicode for character data:

 

DriverID=MySQL
Server=mysrv
Port=3307
Database=addemo
CharacterSet=utf8
User_Name=me
Password=123

 

  • Connect to an embedded server, using Unicode for character data:

 

DriverID=MySQL
Database=addemo
CharacterSet=utf8

 

  • Connect to a remote server, using a SSL connection:

 

DriverID=MySQL
Server=mysrv
Port=3307
Database=addemo
UseSSL=True
SSL_ca=ca-cert.pem
SSL_cert=client-cert.pem
SSL_key=client-key.pem
What do you think about this topic? Send feedback!