目的:在Windows下使用Navicat for MySQL连接Linux下的MySQL得到读表的权限
MySQL创建新用户分配权限
先在Mysql添加一个新的用户
mysql> insert into mysql.user(Host,User,Password) values(‘%’,'test’,password(‘123456’));
然后分配权限
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
eg:test用户在任意主机登录拥有对testdb数据库中user表的所有权限。
mysql>grant all privileges on testdb.user to test@’%’ identified by ‘123456’;
eg:为test分权限,test用户在192.168.1.100上登录有对testdb数据库所有表有增改查的权限。
mysql>grant insert,update,select on testdb.* to test@192.168.1.100 by ‘123456’;
也可以不创建用户直接执行grant语句,系统自动增加,该用户并分配权限。
例:增加一个test用户,密码为123456,只能在192.168.1.** (表示ip范围,最后一位ip随意)上登录,
并对testdb数据库有查询,增加,修改和删除的权限。
mysql>grant select, insert, update, delete on testdb.* to test@’192.168.1.%’ identified by ‘123456’;
权限分配后需要刷新一下
mysql>flush privileges;
需要注意防火墙端口3306是否开放
查看端口状态
/etc/init.d/iptables ststus
修改iptables:
vi /etc/sysconfig/iptables
![]()
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
加入时应注意它一定要在
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT 的上面
然后重启防火墙
service iptables restart
如果还不行就关闭防火墙试试(不建议正式服务器关闭)
service 方式:
开启: service iptables start
关闭: service iptables stop
iptables方式:
查看防火墙状态:
/etc/init.d/iptables status
暂时关闭防火墙:
/etc/init.d/iptables stop
重启iptables:
/etc/init.d/iptables restart