当前位置:Gxlcms > 数据库问题 > C++操作MYSQL遇到的一些问题

C++操作MYSQL遇到的一些问题

时间:2021-07-01 10:21:17 帮助过:17人阅读

将其编码格式定为操作系统自动提供的样式。

二. Plugin caching_sha2_password could not be loaded: 找不到指定的模块。

MySQL provides two authentication plugins that implement SHA-256 hashing for user account passwords《这是官方给的 也只有8以及以上的版本才会遇到这个问题

官方提供了一种插件 来增强 MySQL密码的可靠性 我找了一下相应的api或其他mysql_option()

还真让我找到了一个

MYSQL_OPT_GET_SERVER_PUBLIC_KEY (argument type: bool *)

Enables the client to request from the server the public key required for RSA key pair-based password exchange. 
This option applies to clients that authenticate with the caching_sha2_password authentication plugin.
For that plugin, the server does not send the public key unless requested.
This option is ignored for accounts that do not authenticate with that plugin.
It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.

但是好像c api好像还不能用 亲测不能用,所以我将我的一个用户的默认密码验证从这个插件改回了mysql_native老方式

亲测成功

在这贴上代码 很简单的 《我的问题 有可能不是你们的问题,但还是可以用作参考

 1 #include<errno.h>
 2 #include<stdio.h>
 3 #include<string>
 4 #include<iostream>
 5 #include<mysql/mysql.h>
 6 #define host "localhost"
 7 #define user "root"
 8 #define pass "123"
 9 #define db "msdb"
10 static inline void _mysql_check(MYSQL* con) {
11     fprintf(stderr, "%s", mysql_error(con));
12 //    std::cerr << mysql_error(con) << std::endl;
13     //mysql_close(con);
14     exit(EXIT_FAILURE);
15 }
16 
17 int main()
18 {
19     MYSQL* con=mysql_init(0);
20     MYSQL_RES* result=NULL;
21     MYSQL_FIELD *fd;
22     MYSQL_ROW sql_rom;
23     std::cout << con << std::endl;
24     mysql_options(con,
25         MYSQL_SET_CHARSET_NAME,
26         MYSQL_AUTODETECT_CHARSET_NAME);
27     /*if (!mysql_real_connect(con, host, user, pass, db, 3306, NULL, 0)) {
28         _mysql_check(con);
29     }
30     */
31     con = mysql_real_connect(con, host, user, pass, db, 3306, NULL, 0);
32     if (con) {
33         if (!mysql_select_db(con, db)) {
34             printf("connect successfule \n");
35             mysql_options(con, MYSQL_SET_CHARSET_NAME, "gbk");
36             if (!mysql_query(con, "SELECT * FROM student"))
37             {
38                 result = mysql_store_result(con);
39                 int j = mysql_num_fields(result);
40                 for (int i = 0; fd = mysql_fetch_field(result); i++) {
41                     printf("%s\t", fd->name);
42                 }
43                 printf("\n");
44                 while (sql_rom = mysql_fetch_row(result)) {
45                     for (int i = 0; i < j; i++) {
46                         printf("%s\t", sql_rom[i]);
47                     }
48                     printf("\n");
49                 }
50             }
51         }
52 
53     }
54     mysql_free_result(result);
55     mysql_close(con);
56     getchar();
57     return 0;
58 }

 

C++操作MYSQL遇到的一些问题

标签:mysql   required   cpp   mariadb   not   需要   pat   ima   store   

人气教程排行