数据库安装: 此处有两种安装方式,第一种使用xxx.msi图形化安装方式,和普通的exe软件安装方式一样,按照默认选项一直下一步就可以。mysql下载地址为http://dev.mysql.com/downloads/windows/installer/ 第二种是在mysql官网下载zip压缩包,解压开了就是一
数据库安装:
此处有两种安装方式,第一种使用xxx.msi图形化安装方式,和普通的exe软件安装方式一样,按照默认选项一直下一步就可以。mysql下载地址为http://dev.mysql.com/downloads/windows/installer/
第二种是在mysql官网下载zip压缩包,解压开了就是一个文件夹。zip包下载地址为:http://dev.mysql.com/downloads/mysql/
根据自己的电脑操作系统位数选择相应的版本,否则到时vs链接过不了。
本文只说明第二种安装方式。
1.将mysql-5.6.14-winx64.zip解压缩到C:\mysql目录下,也可以是其它目录,自己随意。进入到C:\mysql\mysql-5.6.14-winx64目录,看到有很多个.ini文件,这个就是数据库的配置文件,不同类型的数据库对应一个.ini文件,你可以设定端口
字符集等等,修改完了之后将文件命名为my.ini,这样mysql server就能识别了。不过如果你没有特殊需要,这个文件是可以不用动的,删除了也可以,所有的配置项mysql自己都有默认值的。
2.运行栏输入cmd,进入命令界面,cd C:\mysql\mysql-5.6.14-winx64\bin,这里放着mysqld.exe命令
将mysql增加到系统服务中:运行命令 mysqld --install 或者 mysqld --install mysql
3.启动mysql服务端:net start mysql (必须启动着 vs才能连接上来,要是数据库连接失败请查看mysql服务是否启动)
4.使用系统管理员身份运行在命令行运行:mysql -uroot 进入之后就可以执行相关的数据库命令了,若只是以mysql进入,则很多命令执行不了,必须以root用户进入,这里没有密码
5.不想使用数据库了就关掉mysql服务,免得占用内存:net stop mysql
删除mysql服务:mysqld --remove mysql
接下来对如何使用MySql的API连接MySql数据库,开发环境为VS2010.
一、VS2010工程设置工作(win32下)
1.首先,建立一个windows应用程序的工程,将项目-->xx属性(xx为自己取的名字)-->配置属性-->C/C++->预处理器->预处理器定义下的_WINDOWS改为_CONSOLE,默认一般已经这样了
2.链接器->系统->子系统 选择为控制台。默认已经这样的就不用动
由于我们要使用Mysql的API,并且我们机子上肯定安装了Mysql数据库,所以我们要将工程的头文件路径指向Mysql安装目录的同文件mysql.h所在的位置,将连接库路径指向libmysql.lib所在的路径,
在我的机子上,Mysql 的安装路径为:C:\mysql\mysql-5.6.14-winx64\include,C:\mysql\mysql-5.6.14-winx64\lib和下面图片不符,自己找自己的目录
高版本的mysql可能没有opt这个目录层次了,只要找到libmysql.lib这个目录就行
我们需要把VS2008的工程中的头文件路径和连接库路径指向上面的两个地方:
将x项目属性页的C/C++->常规->附加包含目录指向:C:\mysql\mysql-5.6.14-winx64\include
将项目属性页的链接器->常规->附加库目录指向:C:\mysql\mysql-5.6.14-winx64\lib
将链接器->输入->附加依赖项中添加libmysql.lib。
如果不设置链接器->输入->附加依赖项中添加libmysql.lib,那么会出现如下的错误:
1>------ 已启动全部重新生成: 项目: MySql-Connect, 配置: Debug Win32 ------
到此处,win32平台已经配置好,可以打开vs写代码连接数据库了,但是x64平台上链接时总是会有以下错误:这是我遇到的问题
error LNK2019: 无法解析的外部符号 _mysql_real_connect@32,该符号在函数 _main 中被引用
后来一想我装的是win7
64位啊,MySQL也是赤裸裸的64位,我用WIN32 项目搞毛线。于是有一个猜想就是,MySQL 64位的lib也是64位的接口。 于是:项目-->xx属性(xx为自己取的名字)--》配置管理器-->活动解决方案平台 下拉后点击新建,会出现自动填写x64,下面一栏不用动,然后将平台改为x64,既可以完成编译链接。
以下是一个简单的例子源代码:工程类型是最简单的windows控制台程序:
//
data_use.cpp : 定义控制台应用程序的入口点。
|

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor