how to Access MYSQL in MT5 (use libmysql.dll)

 
Hi~
I want to use MT5 to directly connect to MYSQL
I found some articles on the Internet but couldn’t connect successfully
Is there any error in my steps?
Please help me correct it
Thank you! ~

I downloaded the x64 version of libmysql.dll file from this webpage
http://www.dlldownloader.com/libmysql-dll/


My code in mql5 is as follows:
//+------------------------------------------------------------------+
//|                                                       123123.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#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); 
#import
 
string   Host       = "127.0.0.1";
string   User       = "abc";
string   Password   = "abc111";
string   Database   = "abc222";
int      Port       = 3306;
string   Socket     = "0";
int      ClientFlag = 0;

int      dbConnectId= 0, res, err;

int OnInit()
{
   connectToDB();
   
   string row; 
   
   string query= "SELECT * FROM ea";
   
   Print("query = " + query);
   int length=StringLen(query); 
   mysql_real_query(dbConnectId,query,length); 
   int result = mysql_store_result(dbConnectId); 
   int numOfRows = mysql_num_rows(result); 
   
   for (int i=0;i<numOfRows;i++) {
      row = mysql_fetch_row(result);
      Print(row);                             //--- Here in row is the result as string typo at the end of the string. In front are some symbols.
   }
   
   mysql_free_result(result);
   
   int myerr = mysql_errno(dbConnectId);
   
   if(myerr > 0) Print("error=",myerr);
   
   EventSetTimer(60);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
   
   mysql_close(dbConnectId);
}

void OnTick()
{
   
   
}

void connectToDB() 
{ 
   dbConnectId= mysql_init(dbConnectId); 
   
   if(dbConnectId != 0) Print("allocated");
   
   res= mysql_real_connect(dbConnectId,Host,User,Password,Password,Port,Socket,ClientFlag); 
   err= GetLastError();
   
   if(res == dbConnectId) Print("connected"); 
   else Print("error=",dbConnectId," ",mysql_errno(dbConnectId)," "); 
   
   
} 


After execution, the error message generated is as follows:


Access violation at 0x000007FEF3C21F30 read to 0x0000000000000000 in 'C:\MyD\MT5\Swissquote Bank MT5\MQL5\Libraries\libmysql.dll'


What is the reason?
thank you all! ~
Download Libmysql.dll for Windows 10, 8.1, 8, 7, Vista and XP (32 Bit and 64 Bit)
Download Libmysql.dll for Windows 10, 8.1, 8, 7, Vista and XP (32 Bit and 64 Bit)
  • 2014.02.28
  • www.dlldownloader.com
link The Libmysql.dll library is 4.23 MB for 32 Bit , 4.5 MB for 64 Bit . The download links are current and no negative feedback has been received by users. It has been downloaded 41001 times since release and it has received 4.5 out of 5 stars . link link The last version of the Libmysql.dll library is the 5.6.21.0 version for 32 Bit and the...
 
Te Fu Chang:
Hi~
I want to use MT5 to directly connect to MYSQL
I found some articles on the Internet but couldn’t connect successfully
Is there any error in my steps?
Please help me correct it
Thank you! ~

I downloaded the x64 version of libmysql.dll file from this webpage


My code in mql5 is as follows:


After execution, the error message generated is as follows:


Access violation at 0x000007FEF3C21F30 read to 0x0000000000000000 in 'C:\MyD\MT5\Swissquote Bank MT5\MQL5\Libraries\libmysql.dll'


What is the reason?
thank you all! ~

Hi, same here, did you solve your problem?

 
Te Fu Chang:Is there any error in my steps?

You try to query the DB after initialization failed.

Reason: