启动chatserver出现问题
jinxin0602 opened this issue · 2 comments
jinxin0602 commented
jasscical commented
我也遇到了这个问题:
[FATAL][[2024-08-17 21:26:38:446]][140280488044352][/home/tom/Desktop/code/flamingo/flamingoserver/chatserversrc/main.cpp:132]Init mysql failed, please check your database config..............
配置如下:
#mysql config
dbserver=127.0.0.1
dbuser=root
dbpassword=123456
dbname=test
jasscical commented
我也遇到了这个问题: [FATAL][[2024-08-17 21:26:38:446]][140280488044352][/home/tom/Desktop/code/flamingo/flamingoserver/chatserversrc/main.cpp:132]Init mysql failed, please check your database config..............
配置如下: #mysql config dbserver=127.0.0.1 dbuser=root dbpassword=123456 dbname=test
修改成dbserver=localhost就可以正常连接mysql服务器了,可以写个简单的程序先验证下连接性
`
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL conn_temp;
// 初始化 MYSQL 结构,如果 mysql 为 NULL,mysql_real_connect 会分配一个
conn = mysql_init(NULL);
// 尝试连接到 MySQL 服务器
//if (mysql_real_connect(conn, "localhost", "root", "123456", "test", 3306, NULL, 0))
if (mysql_real_connect(conn, "localhost", "tom", "123456", "test", 3306, NULL, 0))
{
printf("Connection successful...\n");
// 进行数据库操作...
}
else
{
fprintf(stderr, "Connection failed: %s\n", mysql_error(conn));
}
// 关闭连接
mysql_close(conn);
return 0;
}
`