MySQL创建用户与授权(CentOS6.5)
Posted zendwang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL创建用户与授权(CentOS6.5)相关的知识,希望对你有一定的参考价值。
1.相关SQL语句
#创建用户与授权方法
##本地访问
create user ‘zend‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
grant ALL privileges ON zenddb.* TO ‘zend‘@‘localhost‘;
##本地访问
create user ‘zend‘@‘127.0.0.1‘ IDENTIFIED BY ‘123456‘;
grant ALL privileges ON zenddb.* TO ‘zend‘@‘127.0.0.1‘;
##针对远程访问
create user ‘zend‘@‘%‘ IDENTIFIED BY ‘123456‘;
grant ALL privileges ON zenddb.* TO ‘zend‘@‘%‘;
#刷新权限
flush privileges;
#撤销用户权限 删除用户
REVOKE ALL ON zenddb.* FROM ‘zend‘@‘localhost‘;
DROP USER ‘zend‘@‘localhost‘;
2.退出MySQL,重启服务
/etc/init.d/mysqld restart
3.问题处理
3.1 连接MySQL数据库时出现The dirver has not received any packets from the server
解决办法:查看iptables后发现是端口3306被防火墙阻止
[[email protected] support-files]# vi /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Tue Nov 8 16:07:49 2016 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [1:184] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m tcp --dport 3306 -j DROP -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited -A INPUT -m state --state NEW -m tcp -p tcp --dport 15672 -j ACCEPT COMMIT # Completed on Tue Nov 8 16:07:49 2016
-A INPUT -p tcp -m tcp --dport 3306 -j DROP 修改 -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
接下来,重启服务即可service iptables restart
以上是关于MySQL创建用户与授权(CentOS6.5)的主要内容,如果未能解决你的问题,请参考以下文章