1、停止mysql服务
systemctl stop mysqld.service
2、查看mysql服务my.cnf
locate my.cnf
3、跳过mysql密码验证
vi /etc/my.cnf
在配置文件中添加 skip-grant-tables
注意要在:[mysqld]标签下加入
![]()
4、重启mysql
systemctl restart mysqld.service
5、登录数据库
mysql -u root -p
6、选择库
use mysql;
7、重新修改root密码
select host, user, authentication_string, plugin from user;
alter user user() identified by '复杂的password';
GRANT ALL ON *.* TO 'root'@'%';
GRANT ALL ON 表示所有权限,% 表示通配所有 host,可以访问远程。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234567' WITH GRANT OPTION;
8、刷新权限
flush privileges;
9、退出数据库
exit;
10、删除刚才添加的 skip-grant-tables
vi /etc/my.cnf
11、再次重启mysql
systemctl restart mysqld.service
12、查看firewalld状态
systemctl status firewalld
13、取消防火墙服务锁定
systemctl unmask firewalld;
systemctl status firewalld;
14、设置mysql:3306
firewall-cmd --permanent --zone=public --add-port=3306/tcp
15、刷新
firewall-cmd --reload
如果不行可参考关闭防火墙:
查看防火墙状态: service iptables status
永久性生效,重启后不会复原
开启:chkconfig iptables on
关闭:chkconfig iptables off
即时生效,重启后复原
开启:service iptables start
关闭:service iptables stop
设置后重启:reboot