Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启动chatserver出现问题 #61

Open
jinxin0602 opened this issue Aug 14, 2024 · 2 comments
Open

启动chatserver出现问题 #61

jinxin0602 opened this issue Aug 14, 2024 · 2 comments

Comments

@jinxin0602
Copy link

image
请问一下这个问题怎么解决呀

@jasscical
Copy link

我也遇到了这个问题:
[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
Copy link

我也遇到了这个问题: [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;

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants