MYSQL远程连接设置

1.在服务器端开启远程访问

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

password:可任意设置


2.查看是否已开启

select * from mysql.user where user='root'\G;
​ 出现下图所示,则已开启。

 

3、修改my.cnf文件
找到bind-address = 127.0.0.1这句在前面加个#号注释掉

 

4、远程连接

char server[] = "192.168.0.210";
char user[] = "root";
char passwd[] = "password";
char database[] = "test";

mysql_real_connect(conn,server,user,passwd,database,3306,NULL,0);

posted @ 2022-08-26 11:18  *^VV^*  阅读(913)  评论(0编辑  收藏  举报