1、查看/etc/mysql/my.cnf配置文件是否只允许本地连接
注释配置:#bind-address = 127.0.0.1,重启MySQL Server
2、防火墙(我用的是iptables)禁止了3306端口访问
/etc/sysconfig/iptables配置文件添加3306端口,即添加以下内容再重启防火墙即可:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
3、MySQL没有授予相应权限
授权用户username使用password从任何主机连接到MySQL Server,并允许访问所有数据库所有表
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘username‘@‘%‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION; mysql>FLUSH PRIVILEGES;
允许用户username使用password从IP为192.168.1.9的主机连接MySQL Server,并允许访问所有数据库所有表
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘username‘@‘192.168.1.9‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION; mysql>FLUSH PRIVILEGES;
允许用户username使用password从IP为192.168.1.9的主机连接MySQL Server的dsp数据库下的所有表
mysql>GRANT ALL PRIVILEGES ON dsp.* TO ‘username‘@‘192.168.1.9‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION; mysql>FLUSH PRIVILEGES;
4、修改mysql数据库中user表中相应用户username的host限制
$mysql -h 127.0.0.1 -P 3306 -u root –p mysql>use mysql; mysql>update user set host = ‘%‘ where user = ‘username‘; mysql>select host, user from user;
OK,:)
时间: 2024-10-27 08:18:26