一、安装可视化工具Navicat
链接:https://pan.baidu.com/s/14t2MTbyB3A72H7NcNBLcjQ
提取码:e6o0
解压破解补丁中简体中文64位文件夹下的内容放到Navicat安装文件的目录下。
二、vs环境配置
参考博文:
https://seeky.blog.youkuaiyun.com/article/details/115562097https://seeky.blog.youkuaiyun.com/article/details/115562097实例化(MYSQL* con = mysql_init(NULL);->设置编码(mysql_options())->建立连接(mysql_real_connect())->SQL操作(增删改查)->mysql_close(con);
#include<iostream>
#include<mysql.h>
#include<string>
const char* host = "127.0.0.1";
const char* user = "root";
const char* pw = "199411";
const char* database_name = "student_manager";
const int port = 3306;
using namespace std;
typedef struct Students {
int student_id;
string student_name;
string student_class;
}Student;
int main() {
//建立连接
MYSQL* con = mysql_init(NULL);
//设置编码
mysql_options(con, MYSQL_SET_CHARSET_NAME, "GBK");
if (!mysql_real_connect(con, host, user, pw, database_name, port, NULL, 0)) {
fprintf(stderr,"Failed to connect database!: Error:%s\n",mysql_error(con));
return -1;
}
Student stu{ 112,"sa", "软件1班"};
//定义SQL语句
char sql[1024];
sprintf(sql, "insert into students (student_id,student_name,class_id) values(%d, '%s', '%s')", stu.student_id, stu.student_name.c_str(), stu.student_class.c_str());
if (mysql_query(con, sql)) {
fprintf(stderr, "Failed to insert data!: Error:%s\n", mysql_error(con));
return -1;
}
mysql_close(con);
return 0;
}