本机连接linux数据库,虚拟机linux下连接本机mysq数据库

首先本机安装mysql,登录数据库:

mysql -uroot -p

开启远程访问权限:

grant all privileges on *.* to root@'%' identified by "password";

这里是把本机所有的数据库共享给用户名为root 密码是:password

3.登录虚拟机,安装mysql,写入代码测试:

#include

#include

#include

#include

int main()

{

MYSQL mysql;

if (NULL == mysql_init(&mysql)) {

printf("mysql_init(): %s\n", mysql_error(&mysql));

return -1;

}

if (NULL == mysql_real_connect(&mysql,

"192.168.100.24", //ip or host

"root", // name

"root",//password

"information_schema", //databases name

3306,//port

NULL,

0)) {

printf("mysql_real_connect(): %s\n", mysql_error(&mysql));

return -1;

}

printf("Connected MySQL successful! \n");

return 0;

}

注意:如果使用 gcc ***.c -o 来编译运行的话,会提示找不到mysql.h 文件。使用这个:

gcc -o *** ***.c `mysql_config --cflags --libs`

其中:`是键盘上面数字1旁边那个键,不是单引号!!!

标签:NULL,return,本机,虚拟机,printf,mysq,mysql,include,root

来源: https://blog.csdn.net/suoniyusanxing/article/details/100153526

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值