How to use C ++ to connect Mysql and vsmysql in?
How to use C to connect to Mysql on rupeng's web site has solved the confusion during the sophomore year!
Step 1 download
The installed database is like Peng net Mysql: http://pan.baidu.com/s/1c0m3xIw extraction code: m9sn)
Save on my netdisk (MySQL Server 5.6free installation. Zip): http://pan.baidu.com/s/1jG4KZ8y
Step 2 install
Install the green MYSQL Server:
1) decompress the package to a folder without Chinese characters or spaces
2. Double-click mysqld.exe. if mysqld.exe is in progress, it will be OK.
3) the above method requires manual operation every time the computer is restarted, especially if it is running on the server, it cannot be started before login. Can be registered as a system service: run the command line as an administrator, cd to the bin folder of mysql, execute "mysqld-install", and uninstall the service: mysqld-remove.
* For green MYSQL, the username and password are root.
Step 3 install management tools
Database management tool (Navicat Lite) V9.1.11
: Http://www.cr173.com/soft/44816.html
* Integration of Navicat and Mysql: http://www.rupeng.com/Segments/Index/1800
Step 4: establish the environment
Source (http://www.rupeng.com/Segments/Index/1896)
Step 5 Test
Test code:
# Include <stdlib. h> # include <stdio. h> # include <winsock. h> # include <mysql. h> int main () {MYSQL * mysql = mysql_init (0); return 0 ;}View Code # include <stdlib. h> # include <stdio. h> # include <winsock. h> # include <mysql. h> int main () {MYSQL * mysql = mysql_init (0); if (! Mysql_real_connect (mysql, "localhost", "root", "root", "study3", 0) {printf ("database connection error: % s ", mysql_error (mysql); goto exit; // goto is generally not recommended, but it is useful when handling errors. // there is no absolute good or absolutely bad. Let's look at the level of people using this technology} printf ("connected to the database successfully! \ N "); if (mysql_query (mysql," set names gbk ") {printf (" failed to set connection encoding % s ", mysql_error (mysql); goto exit ;} if (mysql_query (mysql, "insert into T_Users (UserName, Password) values ('I am Chinese', 'aaa123')") {printf ("insertion failed, % s ", mysql_error (mysql); goto exit;} printf (" insert successful \ n "); exit: mysql_close (mysql); // the program must close the connection at last, otherwise, the possibility of too many connections to the mysql server will become stuck: printf ("exit"); getchar (); return 0 ;}View Code
If no error is reported, the connection is successful!
Hope is fulfilled !!
Source: (http://www.rupeng.com/Segments/Index/1896)