MySQL & vs2013

Source: Internet
Author: User
Tags mysql in mysql version mysql for visual studio server port

A MySQL version introduction

On MySQL's official website http://dev.mysql.com/, MySQL is roughly divided into two versions, the free Community Edition (community) and the paid commercial edition (commercial). Commercial version of which can be subdivided, detailed crossing network introduction http://www.mysql.com/products/

Version community: http://dev.mysql.com/downloads/mysql/

Currently out to 5.7. 5.7 and 5.6 If the download is a complete download, the following two tools and MySQL utilities are included. I'm under 5.5 and there's only server.

Download with MSI and zip download, if it is the Windows system will choose to install the MSI directly.

It is particularly important to note that there are 32-bit and 64-bit versions. Choose the version is not to see how many bits of your system, but to see how many bits of the program you build afterwards. For example, if you want to co-program with the famous Win 32 program in VS, choose the 32-bit version.

There are a lot of other tools in the community and commercial versions to help with the MySQL app, and I'm going to say the two tools I've been exposed to.

one is MySQL for Visual Studio, this is auxiliary vs programming, which can visualize the database and table in VS.

: http://dev.mysql.com/downloads/windows/visualstudio/1.2.html

The settings in vs2013 are as follows (I don't know if it's the MySQL for vs function, or the one that's already connected in vs2013)

Another is MySQL Workbench, this is a visual MySQL tool, note that MySQL server and Microsoft SQL Server is not the same, the former is the form of command line. With the workbench, things are much better. But use this to establish a connection to download the MySQL server first, otherwise not connected to the server, but also build what database it.

: http://dev.mysql.com/downloads/workbench/

Two, the connection configuration of MySQL and vs2013

Like all external libraries, using MySQL in VS is nothing more than configuring the following.

To open the properties of the VS project, locate the VC + + Directory tab:

1 Edit the path of the MySQL include folder installation in the additional directory, for example "C:\program files\. \.. \include "

2 Edit the path of the Lib file in the Vault oyster.

Find the linker--input--Additional dependencies added: Libmysql.lib

Find the Libmysql.dll file in the MySQL installation file and put it in the debug (release) folder of the VS project to see what kind of debugging you are using.

If all this is done and there is a problem, try the path in the system environment variable path where there is no MySQL bin folder, plus go.

Third, MySQL and VS2013 joint programming

First to point out the Official Handbook: http://dev.mysql.com/doc/

The following is a program that can be run to read and write to the database and enclose the results

(It involves the database element attribute, and is the default MySQL has the database table in the case , so some of the statements involving mysql_query to see the individual database establishment situation depends on)

#include <Windows.h>#include<string>#include<iostream>#include<mysql.h>#include<stdio.h>#include<io.h>intMain () {//Connectionparams    Char*host ="localhost"; Char*user ="Root"; Char*pass ="***";//your MySQL server password    Char*db ="***";//database databases usedUnsignedintPort =3306;//Server PortMYSQL *sock; Mysql_res*Res; Mysql_field*FD;    Mysql_row ROW; Charszsqltext[ -] =""; inti; intTcreate =0; Sock= Mysql_init (0);//return an initialized mysql* handle or null if there is no enough memory    if(Sock && Mysql_real_connect (sock, host, user, pass, DB,0Null0) ) {Std::cout<<"Connect MySQL succeed!"<<Std::endl; Mysql_set_character_set (sock,"UTF8"); //mysql_query (sock, "set names gb2312");        /*Character-set-server/default-character-set: The server character set, which is used by default.           Character-set-database: Database character set.           Character-set-table: Database table character Set. Priority is increased in turn. So, in general, you only need to set character-set-server, and you do not specifically specify a character set when creating databases and tables, so that the Character-set-server character set is used uniformly. */        //mysql_query (sock, "SET NAMES GBK");//set the encoding format, otherwise the Chinese cannot be displayed under CMD//Connectioncharacter Set//waitfor possibility to check system/mysql mysqlets        if(tcreate) {sprintf_s (Szsqltext, $,"CREATE TABLE ID (ID varchar () NOT NULL primary key,cenroid Float,width int (one)");//construct SQL statement create a new tableStd::cout <<"Create Table id!"<<Std::endl;            GetChar (); Tcreate=1; if(mysql_query (sock, Szsqltext))//executes the Dsql statement and determines if there is an error{std::cout<<"can ' t create table,maybe the Data property is wrong:"<< mysql_error (sock) <<Std::endl; //tcreate = 0;mysql_close (sock); returnFALSE; }} sprintf_s (Szsqltext, $,//Insert data into mytable This table note format                "INSERT into ID1 values (' SL ', ' a ', ' + ')"); Std::cout<<"Insert data to table!"<<Std::endl;            GetChar (); if(mysql_query (sock, Szsqltext)) {std::cout<<"Can ' t insert data to table"<< mysql_error (sock) <<Std::endl;                GetChar ();                Mysql_close (sock); returnFALSE; } sprintf_s (Szsqltext, $,"select* from Id1"); Std::cout<<"select* from id1!"<<Std::endl;            GetChar (); if(mysql_query (sock, Szsqltext))//perform data retrieval and check for errors{mysql_close (sock); returnFALSE; }            Else{std::cout<<"mysql_store_result!"<<Std::endl; Res= Mysql_store_result (sock);//get query results, save the queried data to resi = (int) mysql_num_rows (RES);//number of valid records obtainedStd::cout <<"Query:"<< Szsqltext <<"\ n"<< I <<"Records found:"<<Std::endl;  for(i =0; FD = Mysql_fetch_field (res); i++)//Get column nameStd::cout << Fd->name <<"\ t"; Std::cout<< Std::endl;//output each field name                 while(row = mysql_fetch_row (res))//get specific data, read each record sequentiallyStd::cout << row[0] <<"\ t"<< row[1] <<"\ t"<< row[2] <<"\ t"<<Std::endl; Mysql_free_result (RES); //Releasing result ResourcesGetChar (); }        }        Else//error connecting to database{std::cout<<"cannot connect to the sock sever"<< mysql_error (sock) <<Std::endl;            GetChar ();            Mysql_close (sock); returnFALSE; } mysql_close (sock);//Disconnect Connection//System ("pause");        returnTRUE; }

There's not a bit of alignment.

PS: This article for the author's personal understanding excerpt, welcome correction

MySQL & vs2013

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.