本文目录一览:
- 1、连接mysql数据库时报错:Access denied for user 'root'@'127.0.0.1' (using password: NO)
- 2、c连接Mysql出现的问题
- 3、在DEV C++下,用C和MYSQL进行连接失败
- 4、Linux下C连接MySQL数据库错
连接mysql数据库时报错:Access denied for user 'root'@'127.0.0.1' (using password: NO)
连接mysql数据库时报错:Access denied for user 'root'@'127.0.0.1' (using password: NO)是设置错误造成的,解决方法为:
1、打开并编辑vim /etc/my.cnf。
2、在[mysqld]下方加一行代码Add skip-grant-tables。
3、重启mysql/etc/init.d/mysql restart。
4、使用命令行连接mysql mysql -u root -p。
5、mysql flush privileges。
6、重启mysql /etc/init.d/mysql restart。
c连接Mysql出现的问题
//#include "mysql.h"
你把mysql.h头文件注释掉了,当然编译通不过了。
在DEV C++下,用C和MYSQL进行连接失败
给你个例子:
这个是DEV C++编译通过的
#include windows.h
#include iostream
#include mysql/mysql.h
#define SELECT_QUERY "select * from stu "
using namespace std;
int main(int argc, char *argv[])
{
//connection params
char *host = "localhost";
char *user = "root";
char *pass = "123";
char *db = "mydb";
//sock
MYSQL *sock;
MYSQL_RES *res;
sock = mysql_init(0);
if (sock) cout "sock handle ok!" endl;
else{
cout "sock handle failed!" endl;
return EXIT_FAILURE;
}
//connection
if (mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
cout "connection ok!" endl;
else{
cout "connection failed!" endl;
return EXIT_FAILURE;
}
//query
if (mysql_query (sock, SELECT_QUERY ))
{
cout "Query failed " mysql_error(sock) endl;
exit(1);
}
if ( !( res = mysql_store_result( sock )))
{
cout "Couldn't get result from " mysql_error(sock) endl;
exit(1);
}
MYSQL_FIELD *field;
MYSQL_ROW row;
while ((field = mysql_fetch_field(res)))
{
printf("field name %s ", field-name);
}
while ( row = mysql_fetch_row ( res ))
{
coutrow[0]" "row[1]endl;
}
system("PAUSE");
//closing connection
mysql_free_result ( res );
mysql_close(sock);
return EXIT_SUCCESS;
}
Linux下C连接MySQL数据库错
skipping incompatible /usr/lib/mysql/libmysqlclient_r.a 这里是说这个库文件与当前系统的编译器gcc不一致,你需要确认一下是不是机器位数的问题
gcc -m32 -o test test.c `mysql_config --cflags --libs` 这样试试