CentOS下mysql忘记root密码解决办法,centOS7中Host is not allowed to connect

1,停止mysql服务命令            

systemctl stop mysqld

        2,修改配置文件/etc/my.cnf

            在[mysqld]下添加

           skip-grant-tables

            意思是忽略验证,保存并退出

        3,启动Mysql命令            

systemctl start mysqld

 

         4,修改密码

            执行命令:mysql

            Welcome to the MySQL monitor. Commands end with ; or \g.

            Your MySQL connection id is 3 to server version: 3.23.56
            Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
            mysql> USE mysql ;
            Database changed
            mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
            Query OK, 0 rows affected (0.00 sec)
            Rows matched: 2 Changed: 0 Warnings: 0
            mysql> flush privileges ;
            Query OK, 0 rows affected (0.01 sec)

            mysql> quit

        5,改回配置 :删除 /etc/my.cnf 文件中的 skip-grant-tables,重启服务

            systemctl restart mysqld

 

centOS7中Host is not allowed to connect to this MySQL server解决方法

原因是Centos不允许远程登录mysql

解决办法:

登录 MySQL,执行:mysql -u root -p  (输入密码)
执行: use mysql
执行: update user set host ='%' where user = 'root'; 执行会报错,不影响结果 (如果你不是root登录,修改成你需要的账号)
执行: flush privileges;

posted @ 2020-05-08 14:30  为乐而来  阅读(273)  评论(0编辑  收藏  举报