MySQL用户分配权限
2017-04-24 16:54
281 查看
目的:在Windows下使用Navicat for MySQL连接Linux下的MySQL得到读表的权限
然后分配权限
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
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
相关文章推荐
- Mysql用户密码设置修改和权限分配
- Ubuntu中给mysql添加新用户并分配权限
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- MySQL增加新用户账户、建库、分配权限
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- mysql 新增 删除用户和权限分配
- mysql 新增 删除用户和权限分配
- Linux下给mysql创建用户分配权限
- MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- 向mysql添加新用户并分配权限
- MYSQL新建用户和为用户分配权限的代码
- MySQL用户添加和分配权限
- MySql用户角色管理及权限分配(使用MySQLMembershipProvider和MySqlRoleProvider)
- MySQL 用户权限分配 Grant 语法详解(转)
- 向mysql添加新用户并分配权限
- DB_MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限
- vsftpd+mysql+apache实现给虚拟用户分配不同目录及权限并实现远程管理
- MySql-建用户与分配权限