1、关闭配置
编辑 my.conf,找到 bind-address = 127.0.0.1 将其注释掉
2、删除匿名用户
delete from user where user='';
3、添加用户
grant 权限 on 数据库.表 to '用户名'@'登陆主机' identified by "登陆密码" with grant option;
flush privileges;
4、配置防火墙允许访问数据库端口
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
例子:添加一个root用户,密码为123456,可访问所有权限,登陆主机为192.168.1.100
grant all privileges on *.* to 'root'@'192.168.1.100' identified by "123456" with grant option;
添加一个root用户,密码为123456,可访问所有权限,不限登陆主机
grant all privileges on *.* to 'root'@'%' identified by "123456" with grant option;