The problem when Mysql is used in VC

zhaozj2021-02-16  77

(1) When following the following debug information:

Testnewsql.obj: Error LNK2001: Unresolved External Symbol_Mysql_Close @ 4

Testnewsql.obj: Error LNK2001: Unresolved External Symbol_Mysql_Select_DB @ 8

Testnewsql.obj: Error LNK2001: Unresolved External Symbol_Mysql_Real_Connect @ 32

Testnewsql.obj: Error LNK2001: Unresolved External Symbol_Mysql_init @ 4

Solution:

Add: Project-> setting-> link-> Object / library modules in the VC project:

Libmysql.lib, then compile it.

(2) If it is referenced in other files, in Tools -> Options -> Directories-> Show Directories for: Include Files, these headers are included in the project.

(3) After the compilation is passed, the libmysql.dll file is not found when the running pop-up dialog is found, and the file can be found in the lib / debug directory in the installed mysql directory. Copy it to the compiled release / debug directory. Or add D: / mysql / lib / debug to the "Control Panel" -> System -> "Advanced" -> Environment Variables "-> System Variables ->" PAHT ". Note: D: / MySQL is the mysql directory installed by the author.

(4) If the following compilation problem occurs

Error C2146: SYNTAX Error: missing ';' Before Identifier 'FD'

This is a problem that appears in mysql_com.h. If this sentence is annotated, this compilation problem occurs below:

Error C2065: 'Socket': undeclared Identifier

INT my_connect (my_socket s, const struct socketdr * name, unsigned int namelen, unsigned int Timeout); this function comment out.

The compilation can pass.

Cause Analysis: In the fourth step, Windows Sockets should be selected in the fourth step when creating a document / view with a VC wizard. Otherwise, the above problems will occur when compiling.

The best solution is to add #include to the stdafx.h file to solve the above problems.

(5) If the database is connected, the network should be disconnected when the situation cannot be connected. The reason for the problem occurs.

If a database connection error, then because MYSQL * STDCALL mysql_real_connect (MYSQL * mysql, const char * host, const char * user, const char * passwd, const char * db, unsigned int port, const char * unix_socket, unsigned int Clientflag;

It should be set to NULL for Passwd. For User, you can set it at will.

The reason is temporarily unclear.

In the above case, you can only connect to the user using "root" and you can connect the database.

a. If you identify your identity by other users, you need to add the appropriate user and password. Step 1: Run mysql in the command line mode.

Format: mysql -h host address -u username -P user password

For example: connect to MySQL on this machine.

First open the DOS window, then enter the directory mysqlbin, type the command mysql -uroot -p, then prompt you to lose your password, if you just install MySQL, the superuser root is no password, so you can enter it directly. MySQL, MySQL prompts are: mysql>

2, Example 2: Connect to MySQL on the remote host. Suppose the IP of the remote host is: 110.110.110.110, the username is root, the password is ABCD123. Type the following command:

mysql -h110.110.110.110 -uroot -Pabcd123

Step 2: Add new users

Format: Grant SELECT ON Database. * To Username @ Login Host Identified by "Password"

Example 1. Add a user TEST1 password to ABC, allowing him to log in on any host and have the permissions of all databases, insert, modify, delete. First, use the root user into MySQL, then type the following command:

Grant SELECT, INSERT, UPDATE, DELETE ON *. * to Test1 @ "%" Identified by "ABC";

However, the user of Example 1 is very dangerous. You want someone to know the password of Test1, then he can log in to your MySQL database on any computer on the Internet and to your data for what you want, solution. See Example 2.

Example 2, add a user TEST2 password to ABC, let him log in in localhost, and can query, insert, modify, and delete the database MYDB (localhost refers to the host host, the host where the mysql database is located) In this way, users can use the password that knows Test2, he cannot access the database directly on the Internet, and can only access the web page on the MySQL host.

Grant SELECT, INSERT, UPDATE, DELETE ON MYDB. * to Test2 @ localhost iDentified by "abc"

转载请注明原文地址:https://www.9cbs.com/read-14166.html

New Post(0)