当前位置: 首页 > news >正文

win10安装mysql和c++读取调用举例

一、下载mysql8.rar解压到C盘(也可以解压到其他位置)

在系统环境变量添加JAVA_HOME=C:\myslq8,并在path中添加%JAVA_HOME%\bin;

二、以管理员身份进入命令窗口

三、修改配置文件指定安装路径和数据库的存放路径

四、键入如下命令初始化并启动mysql服务,然后修改登录密码

C:\>mysqld --initialize --user=mysql --console
C:\>mysqld -install
C:\>net start MySQL
C:\>mysql -u root -p (回车让输入的密码就是第一个命令后出现的临时密码
mysql> ALTER USER root@localhost IDENTIFIED BY "12345678"; (新修改密码自己指定
mysql> flush privileges;
mysql> exit

五、手动命令建数据库的命令如下

C:\> mysql -u root -p
Enter password: ******** (上面自己修改的新密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create testdatabase; (创建的数据库为testdatabase
mysql> use testdatabase;  (切换到刚建的数据库
mysql> create table customers (id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(255),address VARCHAR(255),city VARCHAR(255)); (创建表customers
mysql> insert into customers (name,address,city) values('张三','海淀区','北京'); (插入新记录
mysql> select * from customers; (显示新记录
+----+--------+-----------+--------+
| id | name   | address   | city   |
+----+--------+-----------+--------+
|  1 | 张三   | 海淀区    | 北京   |
+----+--------+-----------+--------+
1 row in set (0.00 sec)

六、VS2022调试读取源代码如下

// TestMySQL.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//#include <stdio.h>
#include <iostream>
#include "include/mysql.h"using namespace std;
#pragma comment(lib,"lib/libmysql.lib")int main()
{MYSQL mysql;mysql_init(&mysql);if (!(mysql_real_connect(&mysql, "127.0.0.1", "root", "12345678", "testdatabase", 0, NULL, 0))){cout << "Connect database,fail!\n : ";cout << mysql_error(&mysql);exit(-1);}mysql_query(&mysql, "set names gbk");mysql_query(&mysql, "select * from customers where name = '张三'");MYSQL_RES* res = mysql_store_result(&mysql);if (res == NULL){mysql_close(&mysql);cout << mysql_error(&mysql);exit(-1);}MYSQL_ROW row;int count = mysql_num_fields(res);while (row = mysql_fetch_row(res)){for (int kkk = 0; kkk < count; kkk++){cout << row[kkk] << "\t";}cout << endl;}mysql_free_result(res);mysql_close(&mysql);return 0;
}

七、编译时前要把mysql依赖库和包含文件拷贝到工程下

 八、编译后的运行结果如下

 

http://www.lryc.cn/news/120526.html

相关文章:

  • 计算机竞赛 opencv python 深度学习垃圾图像分类系统
  • 通讯协议037——全网独有的OPC HDA知识一之聚合(六)实际时间最小值
  • 【Freertos基础入门】freertos任务的优先级
  • 【报错】ModuleNotFoundError: No module named ‘websocket‘
  • [Leetcode] [Tutorial] 多维动态规划
  • C语言 二级指针和多级指针
  • 新机器到了要做的事情
  • 个人开发中常见单词拼错错误纠正
  • vb+sql汽车配件管理系统设计与实现
  • Spring Boot+Mybatis实现增删改查接口开发+测试(超详细建议收藏)
  • winform 使用CommonOpenFileDialog选择文件夹或文件
  • EXPLAIN使用分析
  • 布局性能优化:安卓开发者不可错过的性能优化技巧
  • Python 中的机器学习简介:多项式回归
  • docker 容器中执行命令出现错误: 13: Permission denied
  • JavaWeb学习|JavaBean;MVC三层架构;Filter;Listener
  • arx 外部参照文件(XREF)的添加、删除、卸载和重载_objectarx
  • 【博客699】docker daemon预置iptables剖析
  • Golang 中的交叉编译详解
  • Python中的诡异事:不可见字符!
  • 【uniapp】uniapp使用微信开发者工具制作骨架屏:
  • 【UE4 RTS】06-Camera Edge Scroll
  • 无涯教程-Perl - length函数
  • 怎样在 CentOS 里下载 RPM 包及其所有依赖包
  • 在Ubuntu上使用NFS挂载
  • 复现海康威视综合安防管理平台artemis接口Spring boot heapdump内存泄露漏洞
  • 哈希unordered系列介绍(上)
  • MySQL随心记第二篇
  • 0001nginx简介、相关模型与原理
  • elasticsearch简单入门语法