Summary of the process and common problems of connecting VS2019 to MySQL database

Summary of the process and common problems of connecting VS2019 to MySQL database

I started configuring various environments this afternoon, thinking that VS2019 could be used with MySQL. There were many errors in the process, and the configuration was successful around 9 pm as shown below:

Next, let’s talk about the specific steps:

(1) First, prepare the VS2019 and MySQL software, which are available on their respective official websites and will not be repeated here;

(2) Find the installation directory of MySQL and find these two folders as shown in the figure.

(3) After creating a new project, create a main.cpp file to prepare for the following configuration environment.

(4) Open the project properties, click VC++ Directories, and in Include Directories, add the include file path in the MySQL installation directory here, as shown in the following figure:

(5) On the Properties page, open C/C++, select General, follow the same steps as above, and add the include file path in the MySQL file to the Additional Include Directories;

insert image description here

(6) Continue on the property page, click Linker Options, click General, and copy the lib path under the MySQL installation directory to the Additional Library Directory;

insert image description here

(7) Continue in the linker of the property page, click the input option and add the libmysql.lib file. Note that you only need to copy the name libmysql.lib and do not need to add the path. Similarly, this file is also in the lib directory of the mydql installation folder:

insert image description here

(8) Check the platform at the top of the property page and select x64. x32 may cause an error.

insert image description here

(9) Copy bin\libmysql.dll in the MySQL installation directory to c:\windows\system32:

insert image description here

insert image description here

After this installation is complete, you can write test code. The test code is as follows:

#include <stdio.h>
#include <iostream>
#include "my_global.h"
#include "mysql.h"
using namespace std;
int main()
{
	cout << "hello world!" << endl;
	MYSQLmysql;
	MYSQL_RES* res;
	MYSQL_ROW row;
	mysql_init(&mysql);
	mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "gbk");
	//Note: The parameters must be correct.
	//The second parameter is the host address localhost, the third parameter is the user name //The fourth parameter is the user password, the fifth parameter is the connected database //The sixth parameter is the MySQL port number 3306
	if (mysql_real_connect(&mysql, "localhost", "root", "123456",
		"myemployees", 3306, NULL, 0) == NULL) 
	{
		cout << (mysql_error(&mysql));
	}
	mysql_query(&mysql, "SELECT * from myemployees.employees");
	res = mysql_store_result(&mysql);
	//Display data //Assign a value to ROW, determine whether ROW is empty, and print the data if it is not empty.
	while (row = mysql_fetch_row(res))
	{
		printf("%s ", row[0]); //Print ID
		printf("%s ", row[1]); //Print ID
		cout << endl;
	}
	//Free the result set mysql_free_result(res);
	//Close the database mysql_close(&mysql);
	//Stop and wait for getchar();
	system("pause");
	return 0;
}

During the operation, if an error as shown in the following figure occurs, you need to check the configuration environment variables.

1. Right-click the project and check the VC++ directory configuration;

2. Check the input options in the linker

(3) I put the "libmysql.dll and libmysql.lib" files in the .cpp folder of the project.

These three steps can check most of the specific problems.

Be sure to pay attention to the MySQL parameters. If you make a mistake, the following message may appear: Access denied for user 'ODBC'@'localhost' (using password: NO). You can go to the mysql bin directory and enter the command:

mysql -u root -p, check whether the database username and password are correct. The correct input is as shown below:

This is the end of this article summarizing the common problems of connecting VS2019 to MySQL database. For more relevant content about connecting VS2019 to MySQL database, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • VS2019 connects to mysql8.0 database tutorial with pictures and text

<<:  How to increase HTML page loading speed

>>:  How to design a responsive web? Advantages and disadvantages of responsive web design

Recommend

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

Ubuntu installation cuda10.1 driver implementation steps

1. Download cuda10.1: NVIDIA official website lin...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

How to insert weather forecast into your website

We hope to insert the weather forecast into the w...

What is ZFS? Reasons to use ZFS and its features

History of ZFS The Z File System (ZFS) was develo...

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat When the database is replicated betw...

How to Delete Junk Files in Linux Elegantly

I wonder if you are like me, a programmer who arr...

Detailed explanation of common methods of JavaScript arrays

Table of contents Common array methods pop() unsh...

Uniapp WeChat applet: Solution to key failure

uniapp code <template> <view> <ima...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

Django online deployment method of Apache

environment: 1. Windows Server 2016 Datacenter 64...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

Example of adding and deleting range partitions in MySQL 5.5

introduce RANGE partitioning is based on a given ...

MySQL Quick Data Comparison Techniques

In MySQL operation and maintenance, a R&D col...