方法一:
1.编辑mysql配置文件/etc/my.cnf
[root@node3 ~]# vim /etc/my.cnf
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
skip-grant-tables //添加此行内容,表示跳过授权表,跳过密码验证直接进入数据库
......
2.重启数据库,不重启不会生效
[root@node3 ~]# systemctl restart mysqld
3.登录数据库
[root@node3 ~]# mysql -uroot -p
Enter password: //这里直接回车
......
mysql> //出现这个就是进到数据库里了
4.刷新权限,设置密码
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '2356206941';
Query OK, 0 rows affected (0.00 sec)
5. 改回配置文件并重启服务
[root@node3 ~]# vim /etc/my.cnf
skip-grant-tables //删除此行
[root@node3 ~]# systemctl restart mysqld
6.登录
[root@node3 ~]# mysql -uroot -p2356206941
......
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
方法二:
1.编辑mysql配置文件/etc/my.cnf
[root@node3 ~]# vim /etc/my.cnf
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
skip-grant-tables //添加此行内容,表示跳过授权表,跳过密码验证直接进入数据库
......
2.重启数据库,不重启不会生效
[root@node3 ~]# systemctl restart mysqld
3.登录数据库
[root@node3 ~]# mysql -uroot -p
Enter password: //这里直接回车
......
mysql> //出现这个就是进到数据库里了
4.修改表中的数据
mysql> update mysql.user set authentication_string = password('12345678') where User = 'root';
mysql> exit
Bye
5. 改回配置文件并重启服务
[root@node3 ~]# vim /etc/my.cnf
skip-grant-tables //删除此行
[root@node3 ~]# systemctl restart mysqld
6.登录
[root@node3 ~]# mysql -uroot -p12345678
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
版权声明:本文为qq_45948194原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。