c++ mysql_init 返回无效指针_C++操作MYSQL遇到的一些问题

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

二. 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

2 #include

3 #include

4 #include

5 #include

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 intmain()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 <<:endl mysql_options mysql_set_charset_name mysql_autodetect_charset_name host user pass db null _mysql_check>

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

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.cnblogs.com/jijiboy/p/9904797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值