- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,我的问题很简单,我是 C++ 的新手,所以这对某些人来说可能是一个简单的答案,但我正在使用 libmysql 连接到数据库,到目前为止它也能正常工作,我也需要它。但是我希望能够连接到在本地主机上找不到的数据库,该数据库仍将位于我的 LAN 上,但不在本地计算机上。我很确定 unix_socket
参数是我需要更改的所有参数,但我不知道如何或将其更改为什么或如何制作“unix_socket”。下面我将发布我的代码并提前感谢您的帮助谢谢!
void readFromDB(){
skip:
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
/* This If is irrelevant and you don't need to show it. I kept it in for Fault Testing.*/
if(!connect) /* If instance didn't initialize say so and exit with fault.*/
{
fprintf(stderr,"MySQL Initialization Failed");
}
/* Now we will actually connect to the specific database.*/
connect=mysql_real_connect(connect,"10.1.3.253",USER,PASSWORD,DATABASE,3306, NULL,0);
/* Following if statements are unneeded too, but it's worth it to show on your
first app, so that if your database is empty or the query didn't return anything it
will at least let you know that the connection to the mysql server was established. */
if(connect){
printf("First Connection Succeeded\n");
system("PAUSE");
}
else{
printf("Connection Failed!\n");
Sleep(800);
goto skip;
}
MYSQL_RES *result; /* Create a pointer to recieve the return value.*/
MYSQL_ROW row; /* Assign variable for rows. */
//mysql_query(connect,"SELECT * FROM locationTime");
/* Send a query to the database. */
if(!(mysql_query(connect,"SELECT * FROM locationtime") == 0)){
mysql_close(connect);
Sleep(300);
goto skip;
}
result = mysql_store_result(connect); /* Receive the result and store it in res_set */
unsigned int numrows = mysql_num_rows(result); /* Create the count to print all rows */
/* This while is to print all rows and not just the first row found, */
if(numrows != 0){
while ((row = mysql_fetch_row(result)) != NULL){
ids.push_back(row[0]);
dateTime.push_back(row[1]);
locs.push_back(setLocation(row[2]));
strLocs.push_back(row[2]);
imgPaths.push_back(row[3]);
//for(int i = 0; i<(sizeof(row) ); i++){
// //printf("%s\n",row[i] != NULL ? row[i] : "NULL"); /* Print the row data */
//}
//cout<<endl<<endl;
}
}else if(numrows <= 0){
mysql_close(connect); /* Close and shutdown */
mysql_free_result(result);
Sleep(200);
goto skip;
}
mysql_close(connect); /* Close and shutdown */
mysql_free_result(result);
return;
}
这是我的头文件:
#include "my_global.h" // Include this file first to avoid problems
#include "mysql.h" // MySQL Include File
#define SERVER "10.1.3.253"
#define USER "user"
#define PASSWORD "pass"
#define DATABASE "DBName"
最佳答案
通常,如果您在通过 IP 连接时遇到问题,那是因为您的用户帐户不允许从“远程”地址连接。
通常这是通过以下方式解决的:
GRANT ALL PRIVILEGES ON *.* TO `user`@`%` IDENTIFIED BY '...'
user
是您的用户名。显然,您可能希望更多地锁定访问权限。
localhost
用于通过 UNIX 套接字进行“本地”连接。所有其他的都被视为远程。
关于c++ - libmysql mysql_real_connect 因 IP 地址而失败,但适用于 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24615075/
我正在使用 HeidiSQL 编辑 MYSQL 数据库,它询问我想使用哪个库进行编辑: libmysql-6.1.dll libmysql.dll 我怎么知道该使用哪一个? 最佳答案 这些可供选择的
我的目标是将 libmySQL 集成到我的可执行文件中,而不是使用 libmySQL.dll。 我使用 VC++ 2008 @ Windows Vista。 我已经从 http://dev.mysql
我用 libmysql 构建了 gearman。 * CPP Flags: -fvisibility=hidden * LIBS: * LDFLAGS
在使用 libmysqlclient 的 C++ 软件中,我尝试将一行插入包含 html 编码字符(例如 é)的表中。该请求如下所示: INSERT INTO mytable ( field ) V
我第一次尝试使用 dbexpress 组件连接到 mysql 我遇到了这个错误 Failure to Connect : Unable to load libmysql.dll 我的delphi版本:
我试图在cygwin中从源代码构建MySQL的“Connector/C”,但存在一些问题。 -一些背景- 我们可以谈论很多人为什么要在cygwin中使用libmysql。在这种情况下,使用cygwin
我在一个简单的多线程应用程序中使用 libmysql,它将在单核嵌入式系统处理器上运行。我读了here客户端库几乎是线程安全的。 我是否需要序列化我的应用程序(例如,使用互斥体)? 最佳答案 取决于你
我尝试使用以下 AHK 库:http://www.autohotkey.com/board/topic/72629-mysql-library-functions/page-1 我根据他们的示例编写了
我已经安装了 MySQL 5.1.49 和 Visual Studio 2008 二进制 QT 4.6.2。我将 Qt 配置如下: C:\Qt>configure -static -no-webkit
我正在尝试为 MySQL 编写一个 C++ 包装器: cannot open input file 'libmysql.lib' 我确实安装了 mySQL 服务器,但我仍然没有 libmysql.li
我正在尝试使用 libwebsocket 构建我的 WebSocket 服务器,我需要在我的代码中使用 libmysql。我已经安装了 libmysql 并能够使用它,但我不知道如何使用 cmake
我刚刚在 Windows Server 2003 32 位上安装了 MySQL。我有 PHP 5.2.6。 当在 cmd 中执行:php -m 获取模块时出现此错误: "PHP Warning: P
我在 Visual C++ 2010 上的项目中使用 MySql C++ 连接器。在链接器->输入->附加依赖项中我编写了mysqlcppconn-static.lib和libmysql.lib。因此
A 使用 -static 选项和 -qt-sql-mysql 编译了 Qt。一切顺利(编译等,它在我的电脑上运行)。但是当我将程序放在另一台计算机上时,我收到消息“找不到 libmysql.dll..
该程序需要 libmysql.dll 它与 libmysql.lib 位于 c:\xampp\mysql\lib 下。在 Visual C++ 设置中,我将 libmysql.lib 添加到 Link
我安装了 "mysql-installer-community-8.0.16.0.msi" .安装期间一切顺利。我什至可以为我的项目创建一个新的数据库和表。我在 C++ 中使用它。编译和链接一切顺利。
我用 C++ 制作了一个应用程序,它使用 mysql 连接到服务器,但是当我将它发送给我的 friend 进行测试时,他们得到的是:libmysql.dll 不是为在 Windows 上运行而设计的,
当使用 Perl 代码访问 db MYSQL 时,你有没有遇到过这个错误:过程入口点 mysql_get_parameters 不能位于 libmysql_.dll 中? 我已经将libmysql.d
我尝试在我的机器上安装 libmysql++-dev 包但失败并出现以下错误。我已经在机器上完成了 apt-get update 和 apt-get update。 22:28:03-root@deb
我想从应用程序中获取或到达 DLL = C:\mysql\bin\libmysql.dll 行。下面的列表是从 FireDAC 连接器信息中复制的。但是我可以在什么变量、对象或“类”中找到此信息并能够
我是一名优秀的程序员,十分优秀!