第7步、开放远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;
#创建用户与授权方法
##本地访问
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 restart3.问题处理3.1 连接MySQL数据库时出现The dirver has not received any packets from the server<em>解决办法:</em>查看iptables后发现是端口3306被防火墙阻止
[root@zendlinux 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
开启远程访问
设定root用户,使用密码root可以远程访问数据库
GRANT ALL PRIVILEGES ON *.*TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;开放 端口
端口开放后,保存并重启防火墙生效
#开启端口iptables -A INPUT -p tcp -m tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT#保存配置service iptables save#重启生效 service iptables restart #查看规则链 iptables -L -n
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
结果
登录测试,这是登录后的界面
1、create schema [数据库名称] default character set utf8 collate utf8_general_ci;--创建数据库
采用create schema和create database创建数据库的效果一样。
2、create user '[用户名称]'@'%' identified by '[用户密码]';--创建用户
密码8位以上,包括:大写字母、小写字母、数字、特殊字符
%:匹配所有主机,该地方还可以设置成‘localhost’,代表只能本地访问,例如root账户默认为‘localhost‘
3、grant select,insert,update,delete,create on [数据库名称].* to [用户名称];--用户授权数据库
*代表整个数据库
4、flush privileges ;--立即启用修改
5、revoke all on *.* from tester;--取消用户所有数据库(表)的所有权限
6、delete from mysql.user where user='tester';--删除用户
7、drop database [schema名称|数据库名称];--删除数据库
删除用户后在创建失败
drop user admin@localhost;flush privileges;create user admin@localhost identified by 'admins_password'