ubuntumysqlc语言
yiranblade@ubuntu:~$ gcc -Wall mysql_test.c -o mysql_test -lmysqlclient
yiranblade@ubuntu:~$ ./mysql_test
Access denied for user 'root'@'localhost' (using password: YES)
yiranblade@ubuntu:~$
进入mysql什么的都没有问题,不知道为何运行这个C文件会这样
帐号是对的,照着网上的方法装的mysql,然后用给的C代码测试下就成这样了,这是源码:
#include
#include
#include
int main(void)
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char server[] = "localhost";
char user[] = "root";
char password[] = "mima";
char database[] = "mysql";
<code>conn = mysql_init(NULL);if (!mysql_real_connect(conn, server,user, password, database, 0, NULL, 0)){ fprintf(stderr, "%s\n", mysql_error(conn)); exit(1);}if (mysql_query(conn, "show tables")){ fprintf(stderr, "%s\n", mysql_error(conn)); exit(1);}res = mysql_use_result(conn);printf("MySQL Tables inmysql database:\n");while ((row = mysql_fetch_row(res)) != NULL){ printf("%s \n", row[0]);}mysql_free_result(res);mysql_close(conn);printf("finish! \n");return 0}</code>