centos7 启动mysql

密码无法登录问题:

在my.cnf  中加一句   skip-grant-tables ;

重启mysql服务;

mysql -uroot -p;

USE mysql ; 

进入后,修改密码 。UPDATE user SET Password = password ( ‘new-password’ ) WHERE User = ‘root’ ;

flush privileges;

quit;

把my.cn中的skip-grant-tables 去掉。

重启mysql服务;

使用新密码再次登录;

密码正确,但登录不进去:

 mysql库中的user表缺少一个root指向localhost的数据项,导致无法本地登录。

首先kill掉MySQL进程。

然后在启动mysql的参数中加入 --skip-grant-tables  即: /usr/bin/mysqld_safe –skip-grant-tables &

a.那么用root登录呢,输入正确的密码报如下错:

  

b.在本地用mysql命令直接回车可以进入mysql,但是里面只有test和information_schema数据库,没有mysql等数据库

修复root账户丢失的数据项。

最后退出重启;

代码如下:

[root@228827 ~]# systemctl stop mysqld.service
[root@228827 ~]# /usr/bin/mysqld_safe –skip-grant-tables &
[root@228827 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.57 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> use mysql
Database changed
mysql> select user,host,password from user where user='root';
+——+——————-+——————————————-+
| user | host | password |
+——+——————-+——————————————-+
| root | % | *A50E066E106320CF4142 |
| root | centos | *A50E066E106320CF4142 |
| root | 127.0.0.1 | *A50E066E1063608320CF4142 |
+——+——————-+——————————————-+
3 rows in set (0.12 sec)

mysql> update user set host='localhost' where user='root' and host='%';
mysql> flush privileges;
mysql> quit;

[root@228827 ~]# systemctl start mysqld.service

  (如有打扰,请忽略)阿里云ECS大羊群,2U4G低至1.4折,限实名新用户,需要的点吧https://promotion.aliyun.com/ntms/act/vm/aliyun-group/team.html?group=YrliaeMVUn

原文地址:https://www.cnblogs.com/mmady/p/7055481.html