root用户登陆数据库登陆不进去,报以下错误,然后重新修改了密码,具体操作如下:
配置文件中加了skip-grant-tables,用/etc/init.d/mysqld重启之后可以进去了;所以一定是密码的问题,所以我开始改密码。
##我们把root@localhost用户删了,然后有新建了这个用户
mysql> delete from mysql.user where user='root' and host='localhost';
Query OK, 1 row affected (0.01 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
+-----------+-----------+
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.01 sec)
但是到这还是不行,你用下面的命令会发现一个情况
mysql> select * from mysql.user\G;
Grant显示N--mysql权限架构体系(应该是这么说)是关闭的,所以得执行以下操作:
mysql> grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
退出mysql,将skip-grant-tables注掉,然后重启mysql。此时在登陆就可以了。