首先 我使用的是 vcpkg<不知道的可以进行百度 可以剧透一下,这个对Visual Studio使用一些C++的轮子太方便了,

上面是我装的一些库《大大安利vcpkg 安装时一定要使用powershell进行编译 

装上vcpkg后装ligmariadb这个库,这个对Mysql操作还是挺方便的,然后说一下 在装库时碰到的一些问题

1.网络问题

1.参考了一下 github上的答案 将下载失败的url拷下来 自己下 然后再重新开始安装《vcpkg在安装时每一个需要下载的 都会提供url-仔细找,

2.这个问题 也可以隔一短时间 再下载 亲测没有毛病

二. 在使用mysql.h遇到的一些问题

1.Can't initialize character set unknown (path: compiled_in)

这个问题,我查了很多地方,才找到原因,是我当时安装mysql时没有使用cmake将其编译成全部字集使用。这个问题也很好解决,就是使用mysql_option()这个函数,

    mysql_options(con,
MYSQL_SET_CHARSET_NAME,
MYSQL_AUTODETECT_CHARSET_NAME);
//成功返回零,失败返回非零

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

二. 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老方式

亲测成功

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

 #include<errno.h>
#include<stdio.h>
#include<string>
#include<iostream>
#include<mysql/mysql.h>
#define host "localhost"
#define user "root"
#define pass "123"
#define db "msdb"
static inline void _mysql_check(MYSQL* con) {
fprintf(stderr, "%s", mysql_error(con));
// std::cerr << mysql_error(con) << std::endl;
//mysql_close(con);
exit(EXIT_FAILURE);
} int main()
{
MYSQL* con=mysql_init();
MYSQL_RES* result=NULL;
MYSQL_FIELD *fd;
MYSQL_ROW sql_rom;
std::cout << con << std::endl;
mysql_options(con,
MYSQL_SET_CHARSET_NAME,
MYSQL_AUTODETECT_CHARSET_NAME);
/*if (!mysql_real_connect(con, host, user, pass, db, 3306, NULL, 0)) {
_mysql_check(con);
}
*/
con = mysql_real_connect(con, host, user, pass, db, , NULL, );
if (con) {
if (!mysql_select_db(con, db)) {
printf("connect successfule \n");
mysql_options(con, MYSQL_SET_CHARSET_NAME, "gbk");
if (!mysql_query(con, "SELECT * FROM student"))
{
result = mysql_store_result(con);
int j = mysql_num_fields(result);
for (int i = ; fd = mysql_fetch_field(result); i++) {
printf("%s\t", fd->name);
}
printf("\n");
while (sql_rom = mysql_fetch_row(result)) {
for (int i = ; i < j; i++) {
printf("%s\t", sql_rom[i]);
}
printf("\n");
}
}
} }
mysql_free_result(result);
mysql_close(con);
getchar();
return ;
}

C++操作MYSQL遇到的一些问题的更多相关文章

  1. ASP.NET Core 1.0 使用 Dapper 操作 MySql(包含事务)

    操作 MySql 数据库使用MySql.Data程序包(MySql 开发,其他第三方可能会有些问题). project.json 代码: { "version": "1. ...

  2. Python(九) Python 操作 MySQL 之 pysql 与 SQLAchemy

    本文针对 Python 操作 MySQL 主要使用的两种方式讲解: 原生模块 pymsql ORM框架 SQLAchemy 本章内容: pymsql 执行 sql 增\删\改\查 语句 pymsql ...

  3. EF操作MySql

    EF的CodeFrist操作MySql的提前准备: 1.安装两个包:MySql.Data和MySql.Data.Entity,在VS中程序包管理器中添加2个包.(备注需要的VS2015,并且EF6支持 ...

  4. .NET Core 使用Dapper 操作MySQL

    MySQL官方驱动:http://www.cnblogs.com/linezero/p/5806814.html .NET Core 使用Dapper 操作MySQL 数据库, .NET Core 使 ...

  5. asp.net core 1.1 升级后,操作mysql出错的解决办法。

    遇到问题 core的版本从1.0升级到1.1,操作mysql数据库,查询数据时遇到MissingMethodException问题,更新.插入操作没有问题. 如果你也遇到这个问题,请参照以下步骤进行升 ...

  6. 练习:python 操作Mysql 实现登录验证 用户权限管理

    python 操作Mysql 实现登录验证 用户权限管理

  7. Python操作MySQL

    本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...

  8. Python中操作mysql的pymysql模块详解

    Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...

  9. java分享第十七天-03(封装操作mysql类)

     JAVA操作mysql所需jar包:mysql-connector-java.jar代码: import java.sql.*; import java.util.ArrayList; import ...

  10. LightMysql:为方便操作MySQL而封装的Python类

    原文链接:http://www.danfengcao.info/python/2015/12/26/lightweight-python-mysql-class.html mysqldb是Python ...

随机推荐

  1. Spring注解详细

    1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  2. Pycharm安装及第一次使用导航

    Pycharm:Pycharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元 ...

  3. redis相关配置

    redis相关配置1.yum 源码 rpm yum 快速,间接,高效,解决依赖关系,(自动安装到某个路径,不可控),通过yum安装的软件查询命令 rpm -ql nginx yum源的软件包可能版本非 ...

  4. 51nod 1116 K进制下的大数

    你万万想不到,Long Long 就能存下的数据 #include <iostream> #include <cstdio> #include <cstdlib> ...

  5. 转】[MySQL优化]为MySQL数据文件ibdata1瘦身

    原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/2/ 感谢! [MySQL优化]为MySQL数据文件ibda ...

  6. [转]Open Data Protocol (OData) Basic Tutorial

    本文转自:http://www.odata.org/getting-started/basic-tutorial/ Basic Tutorial The Open Data Protocol (ODa ...

  7. Swiper插件轮播

    <html><head> <meta charset="utf-8"> <title>Swiper轮播</title>& ...

  8. GCC的函数声明问题

    Thinking in C++ 第四章 GCC 不需要再MAIN函数前声明 编译也能通过. G++不行.

  9. 【Python】第一个爬虫

    import urllib.request import re class DownPic: def __init__(self,url,re_str): self.url = url self.re ...

  10. 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(三)-----mapGetters

    简单的理解: const getters = { newCount: function(state){ return state.count += 5; } } ------------------- ...