Connection between MT5 and MySQL on 64bit - Access violation

To add comments, please log in or register

For at least 2 years now i have had the same problem in trying to connect to a MySQL database through MQL5 using 64bit architecture (

32bit was fine, but i have just rebuilt my PC and would really like to use 64bit if it is at all possible.

My setup:

  • Windows 10 64bit
  • MT5 64bit build 1881
  • MySQL 64bit build 8.0.12
  • MySQL C connector 64bit (libmysql.dll attached)
  • libmysql.dll placed in ..\MQL5\libraries\

The initialization works fine and returns a non-null value, however the mysql_real_connect() function returns an error of "Access violation at 0x00007FF859046E72 read to 0x0000000031DEF670 in "

Has anyone been able to get around this problem?  I'd be keen to hear if anyone has ever been able to connect to MySQL using 64bit, from searching the forums it seems that most projects are written in 32bit and a lot of people have found the same or similar issues with connecting through 64bit.

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#define DELIM ";" 

//----------------------- DLL IMPORTS
#import "libmysql.dll"
int      mysql_init(int db); 
int      mysql_errno(int TMYSQL); 
int      mysql_real_connect( int TMYSQL,string host,string user,string password, string DB,int port,int socket,int clientflag); 
int      mysql_real_query(int TMYSQL,string query,int length); 
void     mysql_close(int TMYSQL); 
int      mysql_store_result(int TMYSQL); 
string   mysql_fetch_row(int result); 
int      mysql_num_rows(int result); 
void     mysql_free_result(int result); 

int      mysql; 

int OnInit()
//----------------------- OPEN DATABASE CONNECTION

void OnDeinit(const int reason)

void OnTick()


void sub_DB_Connect()
   mysql = mysql_init(mysql); 
   if (mysql!=0) Print("allocated"); 
   string       host               = "localhost"; 
   string       user               = "root"; 
   string       password           = "password"; 
   string       DB                         = "fx"; 
   int          clientflag      = 0; 
   int          port               = 3306; 
   int     socket      = 0; 
   long                 res                     = mysql_real_connect(mysql,host,user,password,DB,port,socket,clientflag); 
   int          err                     = GetLastError(); 
   if (res==mysql) Print("connected"); 
   else Print("error=",mysql," ",mysql_errno(mysql)," "); 

MySQL and 64 bit
MySQL and 64 bit
  • 2016.01.10
Some time ago I had problems with MySQL and 64 bit windows. I solved it by using a 32 bit MT5 on my computer...


Access violation libmysql.dll
Access violation libmysql.dll
  • 2018.05.02
Hello all: Ive been using mysql for working with my EAs for some time now, I used mainly this EAX Library https://www.mql5...
To add comments, please log in or register