1.sudo su # 切换为root用户模式,省的接下来操作的时候出现权限问题
2.mysql -u root -p # 进入mysql命令行模式,需要输入mysql root账号的密码
//GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '********' WITH GRANT OPTION; grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;
3.设置root账号可以远程连接,** 是root账号的密码 如果不成功就多试几次
4.刷新权限
flush privileges
5.exit # 退出mysql命令行
6.lnmp restart # 重启lnmp
查看mysql用户所有权限:
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
参考文档:https://www.cnblogs.com/goodcheap/p/7103049.html
这时候测试连接能否连接mysql了
如果还不行:
需要检查:系统防火墙和安全组配置
安全组策略在阿里云后台添加
系统防火墙:
CentOS7安装iptables防火墙:https://www.linuxidc.com/Linux/2017-10/147238.htm
iptables -nL --line-number
将第三条规则改为ACCEPT:
[root@test ~]# iptables -R INPUT 3 -j ACCEPT
删除第二行规则
[root@test ~]# iptables -D INPUT 2
添加一条规则到尾部:
[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP
再插入一条规则到第三行,将行数直接写到规则链的后面:
[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP
本文为Jsky原创文章,转载无需和我联系,但请注明来自Jsky博客 www.tjin.link