C++操作MYSQL遇到的一些问题
首先 我使用的是 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遇到的一些问题的更多相关文章
- ASP.NET Core 1.0 使用 Dapper 操作 MySql(包含事务)
操作 MySql 数据库使用MySql.Data程序包(MySql 开发,其他第三方可能会有些问题). project.json 代码: { "version": "1. ...
- Python(九) Python 操作 MySQL 之 pysql 与 SQLAchemy
本文针对 Python 操作 MySQL 主要使用的两种方式讲解: 原生模块 pymsql ORM框架 SQLAchemy 本章内容: pymsql 执行 sql 增\删\改\查 语句 pymsql ...
- EF操作MySql
EF的CodeFrist操作MySql的提前准备: 1.安装两个包:MySql.Data和MySql.Data.Entity,在VS中程序包管理器中添加2个包.(备注需要的VS2015,并且EF6支持 ...
- .NET Core 使用Dapper 操作MySQL
MySQL官方驱动:http://www.cnblogs.com/linezero/p/5806814.html .NET Core 使用Dapper 操作MySQL 数据库, .NET Core 使 ...
- asp.net core 1.1 升级后,操作mysql出错的解决办法。
遇到问题 core的版本从1.0升级到1.1,操作mysql数据库,查询数据时遇到MissingMethodException问题,更新.插入操作没有问题. 如果你也遇到这个问题,请参照以下步骤进行升 ...
- 练习:python 操作Mysql 实现登录验证 用户权限管理
python 操作Mysql 实现登录验证 用户权限管理
- Python操作MySQL
本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...
- Python中操作mysql的pymysql模块详解
Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...
- java分享第十七天-03(封装操作mysql类)
JAVA操作mysql所需jar包:mysql-connector-java.jar代码: import java.sql.*; import java.util.ArrayList; import ...
- LightMysql:为方便操作MySQL而封装的Python类
原文链接:http://www.danfengcao.info/python/2015/12/26/lightweight-python-mysql-class.html mysqldb是Python ...
随机推荐
- zoj 2587 Unique Attack【最小割】
拆点拆魔怔了 直接按照原图建就行,这里有个小技巧就是双向边的话不用按着板子建(u,v,c)(v,u,0)(v,u,c)(u,v,0),直接建(u,v,c)(v,u,c)会快十倍!800ms->8 ...
- 初学者的疑惑,到底什么是javaBean?
JavaBeans是Java中一种特殊的类,可以将多个对象封装到一个对象(bean)中.特点是可序列化,提供无参构造器,提供getter方法和setter方法访问对象的属性.名称中的"Bea ...
- postgreSQL 创建user表时引发的表名大写与双引号问题
在postgreSQL里面,user是一个保留字. 如果你想创建user表,你可能会遭遇一些问题! 如图: 可以看到,这里是无法创建user表的. 你可能会说,我只是没有加双引号"" ...
- 解决上传到github报错Successfully created project 'autotest' on GitHub, but initial commit failed:
通过IDEA上传代码到GitHub上可是有时候会碰到这样的问题. 当我们选择VCS->Import into Version Control->Share Project on GitHu ...
- 题解报告:hdu 2058 The sum problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总 ...
- 加密解密(1)HTTPS与HTTP区别
HTTPS简介 HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即 ...
- HDU 5996 博弈
http://acm.hdu.edu.cn/showproblem.php?pid=5996 博弈论待补. 这题变化了一下,因为注意到奇数层的东西(层数从1开始),对手可以模仿地动,那就相当于没动. ...
- python的des和3des加解密
1.加密: pyDes.des(key, [mode], [IV], [pad], [padmode]) pyDes.triple_des(key, [mode], [IV], [pad], [pad ...
- 移动端UI自动化Appium测试——Appium server两种启动方式
执行自动化测试之前,需要先运行appium server,这样才能形成server与java client的通信,启动server有两种方式,一种是命令,一种是按钮图标,具体使用如下: 1.用命令启动 ...
- mysql 忘记密码 登陆+修改密码
step1: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: 进入终端输入:cd /usr/local ...