文章 "如何从 MQL5 (MQL4) 访问 MySQL 数据库" - 页 3

 
my email: 178255721@qq.com
 
 
1982EAcsc :

Hello, it looks like MySQL deny connection for user ODBC on localhost.

You can try to check StackOverflow: http://stackoverflow.com/questions/23950722/how-to-overcome-error-1045-28000-access-denied-for-user-odbclocalhost-u 

how to overcome ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO) permanently
how to overcome ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO) permanently
  • stackoverflow.com
when am trying to open mysql in windows cmd by typing mysql. the following error is occuring. And then by looking similar queries i somehow got a temporary solution by using and then typing the password, is working...
 

Hi Eugeniy Lugovoy,

我使用了MQLMySQL实现了常用的查询、插入、更新、删除操作,但是出现一个问题,不能插入中文,查询出来的中文也是乱码,我想问一下,你中间件封装的过程中有设置编码吗?设置的是什么编码?现象如下:

DROP TABLE IF EXISTS `tb_test_pat`;

CREATE TABLE `tb_test_pat` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `symbol` varchar(255) NOT NULL,

  `start_time` datetime NOT NULL,

  `end_time` datetime NOT NULL,

  `trend` int(10) NOT NULL,

  `points` int(10) unsigned zerofill NOT NULL,

  `comments` text CHARACTER SET utf8,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

插入中文失败 

Error: Query was empty query: INSERT INTO tb_test_pat (trend, symbol, start_time, end_time, points, comments) VALUES (1,'EURUSD','2014.12.16 13:00','2014.12.17 20:00',8,'测试12') 

英文插入成功 

Succeeded: INSERT INTO tb_test_pat (trend, symbol, start_time, end_time, points, comments) VALUES (1,'EURUSD','2014.12.16 13:00','2014.12.17 20:00',8,'abc')


这是为什么?

 
Jiayou Hu:

Hi Eugeniy Lugovoy,

我使用了MQLMySQL实现了常用的查询、插入、更新、删除操作,但是出现一个问题,不能插入中文,查询出来的中文也是乱码,我想问一下,你中间件封装的过程中有设置编码吗?设置的是什么编码?现象如下:

DROP TABLE IF EXISTS `tb_test_pat`;

CREATE TABLE `tb_test_pat` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `symbol` varchar(255) NOT NULL,

  `start_time` datetime NOT NULL,

  `end_time` datetime NOT NULL,

  `trend` int(10) NOT NULL,

  `points` int(10) unsigned zerofill NOT NULL,

  `comments` text CHARACTER SET utf8,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

插入中文失败 

Error: Query was empty query: INSERT INTO tb_test_pat (trend, symbol, start_time, end_time, points, comments) VALUES (1,'EURUSD','2014.12.16 13:00','2014.12.17 20:00',8,'测试12') 

英文插入成功 

Succeeded: INSERT INTO tb_test_pat (trend, symbol, start_time, end_time, points, comments) VALUES (1,'EURUSD','2014.12.16 13:00','2014.12.17 20:00',8,'abc')


这是为什么?

 

You can try to execute next command after MySQL connect:

SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'

Possible some of such settings is not set to UTF.

 

Another one solution to executenext commands one-by-one after connection:

SET NAMES 'utf8'

SET CHARACTER SET 'utf8'

SET SESSION collation_connection = 'utf8_general_ci' 

 
Eugeniy Lugovoy:

Another one solution to executenext commands one-by-one after connection:

SET NAMES 'utf8'

SET CHARACTER SET 'utf8'

SET SESSION collation_connection = 'utf8_general_ci' 

依然不行,不过问题我查到了

bool __stdcall MySqlExecute(int pConnection, wchar_t* pQuery)

{

...

char    Query[16384];

sprintf_s(Query, wcslen(pQuery)+10, "%S", pQuery); // 执行到这行的时候,遇到中文, Query 变成了空的字符串导致错误信息:Error: Query was empty query: UPDATE tb_test_pat SET comments='中文‘

 

你能帮忙修复这个问题吗? 非常感谢!我是64位

 
Jiayou Hu:

依然不行,不过问题我查到了

bool __stdcall MySqlExecute(int pConnection, wchar_t* pQuery)

{

...

char    Query[16384];

sprintf_s(Query, wcslen(pQuery)+10, "%S", pQuery); // 执行到这行的时候,遇到中文, Query 变成了空的字符串导致错误信息:Error: Query was empty query: UPDATE tb_test_pat SET comments='中文‘

 

你能帮忙修复这个问题吗? 非常感谢!我是64位

是的,“sprintf_s”和“sprintf的”不支持中国人。我会想办法帮你解决这个问题
 
还 UTF-8 不能在这种情况下使用,但只 UTF-16
 
Eugeniy Lugovoy:
还 UTF-8 不能在这种情况下使用,但只 UTF-16
什么意思?是用UTF-16?是指设置数据库编码?还是指将中文字符串转成UTF-16?